{"id":10810,"date":"2022-07-18T10:19:49","date_gmt":"2022-07-18T17:19:49","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=10810"},"modified":"2022-07-18T10:20:29","modified_gmt":"2022-07-18T17:20:29","slug":"eliminate-console-app-errors","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/eliminate-console-app-errors\/","title":{"rendered":"Q&#038;A: How do I Eliminate Errors from my C# Console App Windows Service?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/qa-eliminate-errors.webp\" style=\"margin-bottom:20px;\" title=\"How do I eliminate errors from my C# console app Windows Service?\" alt=\"How do I eliminate errors from my C# console app Windows Service?\" width=\"380\" height=\"160\" border=\"0\" \/><\/div>\n<div class=\"blog-qa-question-box\">\n<img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"https:\/\/cdn.coretechnologies.com\/images\/quotes-transparent-21x21.png\" width=\"21\" height=\"21\" \/>&nbsp;&nbsp;For a few years now, our company has been using AlwaysUp to run an internally developed <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/get-started\/csharp\/tutorial-console\" target=\"_blank\" rel=\"noopener\">C# console application<\/a> as a service. The application checks a folder for incoming files and processes anything it finds. It runs every 30 seconds.<\/p>\n<p>The application itself works fine. New files are discovered quickly and we have a system that works reliably 24\/7.<\/p>\n<p>The only problem is that we&#8217;re seeing hundreds of errors in the activity report:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/activity-report-app-restart-errors.png\" class=\"zoomPopup\" title=\"Activity report: Unable to restart the application\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/activity-report-app-restart-errors.png\" title=\"Activity report: Unable to restart the application (click to enlarge)\" alt=\"Activity report: Unable to restart the application \" border=\"0\" width=\"520\" \/><\/a><\/div>\n<p>Have you ever had this reported before? Can you recommend some ways to help us avoid the errors?<\/p>\n<p align=\"right\">&mdash; Clayton<\/p>\n<\/div>\n<p>Hi Clayton. Thanks for supporting our software!<\/p>\n<p>By default, AlwaysUp&#8217;s mission is to run your application 24\/7 &mdash; with no interruptions.<\/p>\n<p>However, your program runs periodically. That&#8217;s perfectly fine, but you should make a couple of tweaks to have AlwaysUp tolerate the frequent stops and starts.<\/p>\n<h2 class=\"blog-caption\">Tweak #1: Minimize the logging around expected starts &amp; stops<\/h2>\n<p>First, understand that AlwaysUp is a chatty babysitter. \ud83d\ude42<\/p>\n<p>Whenever the application it&#8217;s watching starts or stops, AlwaysUp writes an informative entry to the <a href=\"\/products\/AlwaysUp\/AlwaysUp_EventLog.html\">Windows Event Log<\/a>.<\/p>\n<p>For example, you will see one of these messages when AlwaysUp starts (or restarts) your C# program:<\/p>\n<div class=\"code-box\">\n<blockquote><p><b>The application has been started<\/b><\/p><\/blockquote>\n<blockquote><p><b>The application has been restarted (run #number)<\/b><\/p><\/blockquote>\n<\/div>\n<p>And AlwaysUp writes similar entries when the application crashes or stops for any reason.<\/p>\n<p>For customers running applications continuously &mdash; like <a href=\"\/products\/AlwaysUp\/Apps\/RunDropboxAsAService.html\">Dropbox<\/a>, <a href=\"\/products\/AlwaysUp\/Apps\/RunOneDriveAsAService.html\">OneDrive<\/a> or <a href=\"\/products\/AlwaysUp\/Apps\/RunVirtualBoxAsAService.html\">VirtualBox<\/a> &mdash; those messages are helpful. They highlight the rare occasions where the application runs into trouble and needs attention.<\/p>\n<p>But your scenario is different. AlwaysUp launches your application every 30 seconds. As a result, AlwaysUp will inundate your activity log with useless messages.<\/p>\n<p>Fortunately, our team has already designed an easy way to eliminate the spurious log entries. Please:<\/p>\n<ol>\n<li>\n<p>Edit your application in AlwaysUp<\/p>\n<\/li>\n<li>\n<p>Move to the <b>Restart<\/b> tab<\/p>\n<\/li>\n<li>\n<p>Check the <b>Minimize event logging as the application starts &amp; stops<\/b> box:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-minimize-event-logging-win-11.png\" class=\"zoomPopup\" title=\"Minimize Event Logging\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-minimize-event-logging-win-11.png\" title=\"Minimize Event Logging (click to enlarge)\" alt=\"Minimize Event Logging\" border=\"0\" width=\"411\" height=\"592\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Save your changes.<\/p>\n<\/li>\n<\/ol>\n<p>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.<\/p>\n<h2 class=\"blog-caption\">Tweak #2: Make AlwaysUp tolerate &#8220;quick exits&#8221;<\/h2>\n<p>From the detailed logs you sent, each of the three runs completed in less than 1 second. That&#8217;s very fast, and the quick turnaround confuses AlwaysUp.<\/p>\n<p>In fact, because your C# application does its work and exits so quickly, AlwaysUp thinks that your application failed to start at all!<\/p>\n<p>And with that conclusion, AlwaysUp immediately runs your program again.<\/p>\n<p>The result is the cycle you see in your logs &mdash; the repeated, rapid fire running of your console application.<\/p>\n<p>The solution to the problem is to tell AlwaysUp to not to panic if your application completes quickly. To do so:<\/p>\n<ol>\n<li>\n<p>Create an empty file called <b>alwaysup-dont-panic-on-quick-exit.txt<\/b> in your AlwaysUp installation directory (likely <b>C:\\Program Files (x86)\\AlwaysUp<\/b>):<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/create-alwaysup-quick-exit-file.png\" class=\"zoomPopup\" title=\"Create the quick-exit file\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/create-alwaysup-quick-exit-file.png\" title=\"Create the quick-exit file (click to enlarge)\" alt=\"Create the quick-exit file\" border=\"0\" width=\"500\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Restart your application in AlwaysUp.<\/p>\n<\/li>\n<\/ol>\n<p>The presence of that &#8220;magic&#8221; file signals AlwaysUp to tolerate your application&#8217;s speedy exit and avoids the unnecessary restarts.<\/p>\n<p style=\"margin-top: 30px\">\nBest of luck with your C# console application!<\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/restart-remote-service\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: How do I Restart a Windows Service on a Remote Computer?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/restart-remote-service-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: How do I Restart a Windows Service on a Remote Computer?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/multiple-dropbox-accounts\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: Can I Sync Multiple Dropbox Accounts with AlwaysUp?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/run-multiple-dropbox-instances-150x150-2.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: Can I Sync Multiple Dropbox Accounts with AlwaysUp?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/netman-service-warning\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: Why can&#039;t AlwaysUp Open the Netman Service?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/network-service-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: Why can&#039;t AlwaysUp Open the Netman Service?<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;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. &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/eliminate-console-app-errors\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":11125,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[26,284,127],"class_list":["post-10810","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-alwaysup-tag","tag-minimize-logging","tag-qa"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/10810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=10810"}],"version-history":[{"count":19,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/10810\/revisions"}],"predecessor-version":[{"id":11472,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/10810\/revisions\/11472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/11125"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=10810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=10810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=10810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}