Restarting Windows service upon exception

pettrer

Well-known member
Joined
Sep 5, 2008
Messages
92
Programming Experience
10+
Hi,

I have made changes to a colleague's Windows service and it works fine. It's an email service hosted on our web server.

In almost all functions there are try...catch blocks, such as this one:

VB.NET:
...
        Catch ex As Exception
            Fellogg("An error has occured in Sendmail" & ex.ToString)
            S_AllMail = False
        End Try
    End Function

The problem is that when the error is caught, the service won't stop and restart (I have set its properties to always restart upon stopping); it just hangs, which might not be so strange as there is really nothing that tells the service to stop (e.g., Me.Stop() or the like).

What do I need to insert before the End Try in order to actually stop/restart the service, if it's at all possible?

I don't want to do a lot of experimenting as I need to do this live and I hope that one of you knows if there is something I can do to accomplish this task. Surprisingly I haven't found anything on the Internet on this subject, but only what to do when an error ISN'T caught.

Warm regards from a snowy Sweden,

Pettrer
 
I'd suggest that something is happening in your service that is causing the lockup, possibly not related to the error. You might well be better off removing ALL try/catch blocks apart from the one around the ServiceBase.Run call and in the catch for that, use the EventLog.WriteEntry and write a full stack trace.

Don't forget that you can attach the debugger to an already running process if you copy the relevant PDB files out along side the exe
 
Back
Top