Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Windows Service is crashing

Reply
 
Old 03-16-2009   #1 (permalink)
Jason Barnett


 
 

Windows Service is crashing

I'm not sure if this is the correct discussion group, so please advise me of
a better one if applicable.

I've created a windows service using v2.0 Framework. VS2005 created a
Program class, containing my Main method that instantiates and runs my
service. I've overridden the OnStart method to create a thread for
asynchronous processing. Within the thread's execution method, I call a
method on a referenced assembly to perform some work.

I've added try-catch blocks within every step to capure any Exception
object; within Main method, OnStart method, thread's execution method, and
referenced assembly's public method. However, My service displays an
"Unhandled Exception" popup, asking me if I want to debug. I don't
understand how any exception is getting by my error handling. Also, I don't
understand how to debug the process, since I can't attach it within VS2005
(it crashes too quickly), and the debug dialog doesn't bring me to any line
of code when I point it to an existing instance of my project.

Could someone please advise me what steps I can take to investigate and
resolve the issue?

My System SpecsSystem Spec
Old 03-16-2009   #2 (permalink)
Jeroen Mostert


 
 

Re: Windows Service is crashing

Jason Barnett wrote:
Quote:

> I'm not sure if this is the correct discussion group, so please advise me of
> a better one if applicable.
>
> I've created a windows service using v2.0 Framework. VS2005 created a
> Program class, containing my Main method that instantiates and runs my
> service. I've overridden the OnStart method to create a thread for
> asynchronous processing. Within the thread's execution method, I call a
> method on a referenced assembly to perform some work.
>
> I've added try-catch blocks within every step to capure any Exception
> object; within Main method, OnStart method, thread's execution method, and
> referenced assembly's public method. However, My service displays an
> "Unhandled Exception" popup, asking me if I want to debug. I don't
> understand how any exception is getting by my error handling. Also, I don't
> understand how to debug the process, since I can't attach it within VS2005
> (it crashes too quickly), and the debug dialog doesn't bring me to any line
> of code when I point it to an existing instance of my project.
>
> Could someone please advise me what steps I can take to investigate and
> resolve the issue?
Add a handler to the AppDomain.UnhandledException event and have that log
the exception to somewhere useful. All managed exceptions pass through
there. If your problem is an exception in unmanaged code, you should see a
CLR error in the event log instead.

Also, for easier debugging of services, enable them to run as console
applications. This will not replicate the service environment (so if your
problem has to do with that it won't help) but it's very useful for
hammering out functional bugs without reinstalling every time. To do this,
change your .Main method to read something like this:

public static void Main(string args[]) {
if (Environment.UserInteractive) {
// not a service
MyService s = new MyService();
s.OnStart();
Console.ReadLine();
s.OnStop();
} else {
ServiceBase.Run(new MyService());
}
}

(Untested, but the general idea is sound.)

--
J.
My System SpecsSystem Spec
Old 03-16-2009   #3 (permalink)
Jason Barnett


 
 

Re: Windows Service is crashing

Thank you so much. By running it as a Console Application I was EASILY able
to identify the issue and correct it.

I also added the handler to the AppDomain.UnhandledException event to ensure
that nothing else will be missed (even if somethine strange happens in
production).

I appreciate your help.


"Jeroen Mostert" wrote:
Quote:

> Jason Barnett wrote:
Quote:

> > I'm not sure if this is the correct discussion group, so please advise me of
> > a better one if applicable.
> >
> > I've created a windows service using v2.0 Framework. VS2005 created a
> > Program class, containing my Main method that instantiates and runs my
> > service. I've overridden the OnStart method to create a thread for
> > asynchronous processing. Within the thread's execution method, I call a
> > method on a referenced assembly to perform some work.
> >
> > I've added try-catch blocks within every step to capure any Exception
> > object; within Main method, OnStart method, thread's execution method, and
> > referenced assembly's public method. However, My service displays an
> > "Unhandled Exception" popup, asking me if I want to debug. I don't
> > understand how any exception is getting by my error handling. Also, I don't
> > understand how to debug the process, since I can't attach it within VS2005
> > (it crashes too quickly), and the debug dialog doesn't bring me to any line
> > of code when I point it to an existing instance of my project.
> >
> > Could someone please advise me what steps I can take to investigate and
> > resolve the issue?
>
> Add a handler to the AppDomain.UnhandledException event and have that log
> the exception to somewhere useful. All managed exceptions pass through
> there. If your problem is an exception in unmanaged code, you should see a
> CLR error in the event log instead.
>
> Also, for easier debugging of services, enable them to run as console
> applications. This will not replicate the service environment (so if your
> problem has to do with that it won't help) but it's very useful for
> hammering out functional bugs without reinstalling every time. To do this,
> change your .Main method to read something like this:
>
> public static void Main(string args[]) {
> if (Environment.UserInteractive) {
> // not a service
> MyService s = new MyService();
> s.OnStart();
> Console.ReadLine();
> s.OnStop();
> } else {
> ServiceBase.Run(new MyService());
> }
> }
>
> (Untested, but the general idea is sound.)
>
> --
> J.
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Is Windows Mail supporting Hotmail as a free service or is it a paid service Vista mail
The Windows Firewall service terminated with service-specific erro Vista security
Security Service and Windows Wireless Service stopped working Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46