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

  • SEARCH
  • Home
  • 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 8386217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:52:31+00:00 2026-06-09T17:52:31+00:00

I have a C# 4.0 Windows Console application which should run 24*7*365. (I have

  • 0

I have a C# 4.0 Windows Console application which should run 24*7*365. (I have a Windows Service to watch for this application, and start it if it terminates for some reason). The startup of this Console application involves some complex resource consuming activities – so I have to make sure that no frequent restarts of the console application happens. The console application has 3 System.Timers.Timer instances which do some activities when the timers are elapsed (intervals are 10 seconds, 15 seconds and 2 hours resp). What would be the correct method to prevent the console application from terminating, and keep it alive? Could someone please suggest!

  • 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-09T17:52:33+00:00Added an answer on June 9, 2026 at 5:52 pm

    From what you have said in your comments the only reason you have a console application is so you can read debugging messages. This answer will go off that assumption.

    A console app is not reliable enough to do what you want to do, there are many situations that you will encounter that the app will not launch or may launch multiple times (what do you do if no one is logged in? What do you do if multiple people are logged in?)

    The best thing to do is write this intensive operation as a service, then whatever diagnostic information you where outputting to the console you can either put it to the event log or put it to the Debugger.

    If you want to write a message to the Application event log all you need to do is write your information to this.EventLog.WriteEntry(message). This will generate a Information event in the Application Event Log for your service. If you want to raise the severity to Warning or Error, you just need to use the other overload.

    If you want to write to a different log than Application (like your own log) you will need to have the installer of the service create whatever sources/logs you need (ask a new question if you need help with this). Then set AutoLog in your service to false then create your own event log instance pointing at your new log.

    If you want logs that only show up when you are diagnosing a problem the simplest solution is to change your Console.WriteLine(message) statements to Debugger.Log(1, "DebugLogging", message + Environment.NewLine). This will cause your messages to show up in the “Debug” output window when you are attached to the service while it is running (Do you know how to attach to a service to run your debugger on it? If not ask a new question on it). I would not recommend using Debug.WriteLine(message) unless you never plan on doing diagnostics while built in release mode. This is because Debug.WriteLine has the attribute [Conditional("DEBUG")]. What this does is cause the the function only to be executed if the DEBUG flag is set during compile time, and Release does not have that flag set.


    That is the simple solution, if you want a more robust solution I recommend learning how to use log4net. Log4net will let you do all of the above, plus a lot more. For example you can control how much gets written to the event logs via a configuration file (The program does not even need to be restarted to start logging with the new settings, it detects when you perform a save.)

    This way you can put verbose logging messages in your code but only turn them on when you need them by changing one setting in a XML config file.

    If you have any questions about setting up either of the two top suggestions or setting up log4net feel free to start new questions on those topics.

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

Sidebar

Related Questions

I have a simple .NET application which runs as Windows Service. Say it has
I have a simple console application which runs daily (called by windows task scheduler)
I have a console application which i need to host as an independant windows
I have a console application in C# in which I run various arcane automation
I have created a console application which run selenium test and open up browser,
I have created my c# console application as windows service and installed the service
I have a console application from which I create a window. I can render
I'm creating a Windows Console application written in VB.NET and I have a few
Iam beginner to windows services , i have a console application to transfer files
I have a solution that contains both a Windows Forms application and a Console

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.