The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Q&A: How do I Eliminate Errors from my C# Console App Windows Service?

How do I eliminate errors from my C# console app Windows Service?
  For a few years now, our company has been using AlwaysUp to run an internally developed C# console application as a service. The application checks a folder for incoming files and processes anything it finds. It runs every 30 seconds.

The application itself works fine. New files are discovered quickly and we have a system that works reliably 24/7.

The only problem is that we’re seeing hundreds of errors in the activity report:

Activity report: Unable to restart the application

Have you ever had this reported before? Can you recommend some ways to help us avoid the errors?

— Clayton

Hi Clayton. Thanks for supporting our software!

By default, AlwaysUp’s mission is to run your application 24/7 — with no interruptions.

However, your program runs periodically. That’s perfectly fine, but you should make a couple of tweaks to have AlwaysUp tolerate the frequent stops and starts.

Tweak #1: Minimize the logging around expected starts & stops

First, understand that AlwaysUp is a chatty babysitter. 🙂

Whenever the application it’s watching starts or stops, AlwaysUp writes an informative entry to the Windows Event Log.

For example, you will see one of these messages when AlwaysUp starts (or restarts) your C# program:

The application has been started

The application has been restarted (run #number)

And AlwaysUp writes similar entries when the application crashes or stops for any reason.

For customers running applications continuously — like Dropbox, OneDrive or VirtualBox — those messages are helpful. They highlight the rare occasions where the application runs into trouble and needs attention.

But your scenario is different. AlwaysUp launches your application every 30 seconds. As a result, AlwaysUp will inundate your activity log with useless messages.

Fortunately, our team has already designed an easy way to eliminate the spurious log entries. Please:

  1. Edit your application in AlwaysUp

  2. Move to the Restart tab

  3. Check the Minimize event logging as the application starts & stops box:

    Minimize Event Logging
  4. Save your changes.

That adjustment will prevent AlwaysUp from filling up your event logs. Restart your C# application and you will notice that the activity report is much less verbose.

Tweak #2: Make AlwaysUp tolerate “quick exits”

From the detailed logs you sent, each of the three runs completed in less than 1 second. That’s very fast, and the quick turnaround confuses AlwaysUp.

In fact, because your C# application does its work and exits so quickly, AlwaysUp thinks that your application failed to start at all!

And with that conclusion, AlwaysUp immediately runs your program again.

The result is the cycle you see in your logs — the repeated, rapid fire running of your console application.

The solution to the problem is to tell AlwaysUp to not to panic if your application completes quickly. To do so:

  1. Create an empty file called alwaysup-dont-panic-on-quick-exit.txt in your AlwaysUp installation directory (likely C:\Program Files (x86)\AlwaysUp):

    Create the quick-exit file
  2. Restart your application in AlwaysUp.

The presence of that “magic” file signals AlwaysUp to tolerate your application’s speedy exit and avoids the unnecessary restarts.

Best of luck with your C# console application!

Posted in AlwaysUp | Tagged , , | 4 Comments

4 Responses to Q&A: How do I Eliminate Errors from my C# Console App Windows Service?

  1. l says:

    I think it should be better to add an option to ignore “quick exits” in the task configuration. Usually such requirements are for specific tasks. Now the method of creating a new file is globally effective, and it is not friendly to ordinary users.

  2. Hi.

    At it’s core, running an application as a Windows Service can be very complicated. You can get an idea of that when you look at AlwaysUp’s interface, which presents over 40 sophisticated knobs and levers!

    As you might expect, not all features will interest every user. Our team must carefully balance complexity and usability and artfully guard what “complicates” the user interface. Because of that, not every capability makes it to an option in the GUI. In fact, when a new feature’s value has not been demonstrated, we may provide a less user-friendly way for a customer to get the job done. And that is what happened with the “tolerate quick exits” feature.

    Of course, we continue to gather feedback from our customers using the product to make the best decisions about improvements. In this case, if we find that more than a handful of our users will benefit from the “tolerate quick exits” feature, we will promote it to a first-class option, easily settable from the user interface.

    Thank you for your input!

  3. l says:

    Hi, this request is made because alwaysup not only keeps the task running, but also can be easily used as a timed task scheduler, I use both functions at the same time, so allowing a single task “quick exits” would be a reasonable request. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *