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 778059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:42:21+00:00 2026-05-14T19:42:21+00:00

Below is the usual Program.cs content for a windows service program: static class Program

  • 0

Below is the usual Program.cs content for a windows service program:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new MyService() 
        };
        ServiceBase.Run(ServicesToRun);
    }
}

Is it a bad practice to enclose the ServiceBase.Run(...) in a try-catch block?

Thanks.


EDIT:

Performed some tests and found (test method: send a custom command to the service, which throws an ApplicationException in the OnCustomCommand override):

A. Enclosing ServiceBase.Run() in try/catch does not catch the exception thrown in OnCustomCommand, because the try block was already in scope when the service thread started executing. Therefore, questioning the corectness of this method is irrelevant as long as it doesn’t fill its purpose anyway.

B. Adding a handler for AppDomain.CurrentDomain.UnhandledException did not catch the exception either.

However, in both cases the exception showed up in the Windows event log. This pretty much solves my need of knowing when something crashes during service execution but the question remains: are there any cases when a service may silently crash without any trace in the event log?

  • 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-05-14T19:42:21+00:00Added an answer on May 14, 2026 at 7:42 pm

    That depends on what you are doing. If you intend to treat exceptions and do something useful with them (e.g. retry, run a backup, notify the user and ask for feedback etc) then IMO I do not think this is a bad practice.

    As I said, it depends on what you are doing.

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

Sidebar

Related Questions

Below is the code from internalRegister method of GCMRegistrar class static void internalRegister(Context context,
below is the code Code : #include <stdio.h> int main(void) { int ch; while((ch
Given the code below ... Net::HTTP.start('localhost', 4000) do |http| # # usual stuff omitted
Below is my main activity file. I am stuck with the bottom area (commented
The attached below C code when run gives the error summary: malloc.c:3074: sYSMALLOc: Assertion
My application has to deal with large amounts of data, usual select size is
The below project of mine works fine with OpenGL on Windows and the Mac
I have two classes in python Drunk Usual Drunk The usual drunk class inherits
Trying to force-download file with PHP using usual: header(Content-type: $type ); header(Content-Disposition: attachment; filename=$name);
I am having the usual errors within header files, as listed below. Error 54

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.