473,388 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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
Mar 6 '07 #1
3 5959
On 6 Mar, 12:22, Simon Harvey <notha...@hotmail.comwrote:
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_Unhan dledException);

That hooks up to my exception handler:

private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs pArgs)
{
PublishException((Exception)pArgs.ExceptionObject) ;

}

Mar 6 '07 #2
On Mar 6, 1:42 pm, "DeveloperX" <nntp...@operamail.comwrote:
On 6 Mar, 12:22, Simon Harvey <notha...@hotmail.comwrote:
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_Unhan dledException);

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

Mar 7 '07 #3
os******************@googlemail.com wrote:
On Mar 6, 1:42 pm, "DeveloperX" <nntp...@operamail.comwrote:
>On 6 Mar, 12:22, Simon Harvey <notha...@hotmail.comwrote:
>>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_Unha ndledException);

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

Simon
Mar 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Derek Wolf | last post by:
I am having some difficulties implementing an UnHandledException handler for the AppDomain.UnhandledException event in a windows service for unhandled exceptions that occur on a System.Timers.Timer...
0
by: Jiho Han | last post by:
This seems like a often-asked topic. I created a windows service and installed it on my workstation. The application basically goes out and "receieves" messages from a queue on a remote server....
9
by: Claudio Di Flumeri | last post by:
Hello all, I've added a global exception handler to my application in this way: Sub Main() AddHandler Application.ThreadException, AddressOf ThreadException AddHandler...
7
by: Adam J. Schaff | last post by:
I would like my windows service application to log all exceptions that occur, on any of its threads, to the windows event log. Is this possible? If so, can anyone give me an example of the...
3
by: Masa Ito | last post by:
I am trying to follow the great advice that seems to be said over and over by good people (like Jay Harlow) about putting a global exception handler in Sub Main. Our app has Sub Main in a...
1
by: Samuel Shulman | last post by:
Hi Is there a global exception handler for ASP.NET application? and can that be/is implemented? Thank you, Samuel
1
by: =?Utf-8?B?cm9zczYxMw==?= | last post by:
I'm puzzled by an error message encountered while creating a Windows Service. In particular, I'm creating a second Windows Service within a Windows Service project, using Visual Studio 2005. The...
5
by: =?Utf-8?B?cnZhbmdlbGRyb3A=?= | last post by:
Hello, I have a problem with our OnlineBackupService.exe. This is a Windows Service which is built in .Net 1.1 and basically grabs files from the file system and will try to upload them using...
2
by: teejayem | last post by:
I am having problems creating a Windows Service using Visual Studio 2005. Code as follows:- Imports System.IO Imports System.Net.Mail
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.