|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Global exception handler when creating a windows service?Hi all,
What is the best way to catch any and all exceptions when creating a windows service application? Is there some sort of global exception event I can use, or is it possible to surround the ServiceBase.Run(ServicesToRun); line with a try catch? Would that work? Also, when an exception occurs within a service, does it automatically shut down? Thanks to anyone who can advise Kindest Regards Simon On 6 Mar, 12:22, Simon Harvey <notha***@hotmail.com> wrote:
Show quote > Hi all, When you start use:> > What is the best way to catch any and all exceptions when creating a > windows service application? Is there some sort of global exception > event I can use, or is it possible to surround the > > ServiceBase.Run(ServicesToRun); > > line with a try catch? Would that work? > > Also, when an exception occurs within a service, does it automatically > shut down? > > Thanks to anyone who can advise > > Kindest Regards > > Simon AppDomain.CurrentDomain.UnhandledException+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); That hooks up to my exception handler: private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs pArgs) { PublishException((Exception)pArgs.ExceptionObject); }
Show quote
On Mar 6, 1:42 pm, "DeveloperX" <nntp***@operamail.com> wrote: Also you can use try/catch block in Main() method.> On 6 Mar, 12:22, Simon Harvey <notha***@hotmail.com> wrote: > > > > > Hi all, > > > What is the best way to catch any and all exceptions when creating a > > windows service application? Is there some sort of global exception > > event I can use, or is it possible to surround the > > > ServiceBase.Run(ServicesToRun); > > > line with a try catch? Would that work? > > > Also, when an exception occurs within a service, does it automatically > > shut down? > > > Thanks to anyone who can advise > > > Kindest Regards > > > Simon > > When you start use: > > AppDomain.CurrentDomain.UnhandledException+=new > UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); > > That hooks up to my exception handler: > > private static void CurrentDomain_UnhandledException(object sender, > UnhandledExceptionEventArgs pArgs) > { > PublishException((Exception)pArgs.ExceptionObject); > > } Best regards Oscar Acosta oscar.acostamonte***@googlemail.com wrote:
Show quote > On Mar 6, 1:42 pm, "DeveloperX" <nntp***@operamail.com> wrote: Many thanks>> On 6 Mar, 12:22, Simon Harvey <notha***@hotmail.com> wrote: >> >> >> >>> Hi all, >>> What is the best way to catch any and all exceptions when creating a >>> windows service application? Is there some sort of global exception >>> event I can use, or is it possible to surround the >>> ServiceBase.Run(ServicesToRun); >>> line with a try catch? Would that work? >>> Also, when an exception occurs within a service, does it automatically >>> shut down? >>> Thanks to anyone who can advise >>> Kindest Regards >>> Simon >> When you start use: >> >> AppDomain.CurrentDomain.UnhandledException+=new >> UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); >> >> That hooks up to my exception handler: >> >> private static void CurrentDomain_UnhandledException(object sender, >> UnhandledExceptionEventArgs pArgs) >> { >> PublishException((Exception)pArgs.ExceptionObject); >> >> } > > Also you can use try/catch block in Main() method. > Best regards > Oscar Acosta > Simon |
|||||||||||||||||||||||