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 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

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Give this a try: $currentCatIds = $_product->getCategoryIds(); and also $categoryCollection… May 16, 2026 at 10:08 am
  • Editorial Team
    Editorial Team added an answer Animation.setFillAfter(true) might be what you are looking for. May 16, 2026 at 10:08 am
  • Editorial Team
    Editorial Team added an answer items.Where(i=>i.sid == 123).ToList().ForEach(i=>i.sid = 456); or rather use normal foreach… May 16, 2026 at 10:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Please see the code below: #include <windows.h> int main(int argc, char* argv[]) { HANDLE
Today I experienced a weird problem while trying to remotely debug an application built
I am trying to compile and run a simple java class within eclipse. The
Below is the use case: I have a unique index defined on 3 columns
Below is my code: if(settings.controlNav){ $('.nivo-controlNav', slider).hide(); slider.hover(function(){ $('.nivo-controlNav', slider).show('slow'); }, function(){ $('.nivo-controlNav', slider).hide('slow');
Below is an image of the problem. I've tried correcting the folder permissions to
Comparing two codes below,both do the same,but with slighty differences: ALTER procedure [dbo].[SP_USUARIOS_UPDATE] @usu_ds
Why is it that below code prints 'None' as well as what I tell
I expected the code below to print Hello, world! every 5 seconds, but what
Using the below XML, I need to figure out which person worked more hours

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.