Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:33:55+00:00 2026-06-14T09:33:55+00:00

I have a console application that I would like to keep open all of

  • 0

I have a console application that I would like to keep open all of the time while still listening in to events. I have tested Thread.Sleep(Timeout.Infinite); and while (true) { } and both allow the events to be raised while keeping the console application open. Is there one that I should be using over the other? If the thread is sleeping, is there anything that I should not be doing, such as modifying a static collection declared in the scope of the class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:33:57+00:00Added an answer on June 14, 2026 at 9:33 am

    I would recommend using a ManualResetEvent (or other WaitHandle), and calling ManualResetEvent.WaitOne.

    This will have a similar effect to sleeping forever, except that it provides you a clean way to exit from your infinite “block” when desired (by calling Set() on the event).

    Using while(true) will consume CPU cycles, so it’s definitely something to avoid.

    is there anything that I should not be doing, such as modifying a static collection declared in the scope of the class?

    In general, no. Since your thread will be blocked, there shouldn’t be any synchronization issues with using shared data (provided the items within the collection don’t have specific requirements, such as user interface elements which must be used on a thread with a proper synchronization context.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic C# console application that I would like to run as
I have a console application that i got to make and i would like
I have a Console Application that instantiates a Quartz Scheduler. I would like a
I have a console application that I would like to run as 'NT AUTHORITY\NetworkService',
I have the following code piece for a console application that I would like
I'm creating a console application where I would like to have two outputs and
I have a simple application that I would like to sort of automate via
I would like to have a C# console application print the extended ASCII Codes
I have a button in my obj-c application that I would like to launch
Basically, I have an application that runs every 15 minutes. I would like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.