Interrupting service startup
-
Hello, I am writing my first Windows Service in .Net (4.0, VS2010), and I am getting the results I expect, but there is one thing I would like to optimize, but do not know how.. and googlin' it has been infructuous so far.. Basically, I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config). It's all ok when everything loads well, but I have no idea how to abort the startup when an error is encountered. Any idea ? Thanks in advance, Best regards, Fred
-
Hello, I am writing my first Windows Service in .Net (4.0, VS2010), and I am getting the results I expect, but there is one thing I would like to optimize, but do not know how.. and googlin' it has been infructuous so far.. Basically, I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config). It's all ok when everything loads well, but I have no idea how to abort the startup when an error is encountered. Any idea ? Thanks in advance, Best regards, Fred
Fred2834 wrote:
I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config).
I would assume throwing an exception would suffice. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Hello, I am writing my first Windows Service in .Net (4.0, VS2010), and I am getting the results I expect, but there is one thing I would like to optimize, but do not know how.. and googlin' it has been infructuous so far.. Basically, I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config). It's all ok when everything loads well, but I have no idea how to abort the startup when an error is encountered. Any idea ? Thanks in advance, Best regards, Fred
There's various ways of doing it, with equally various opinions on what's appropriate. The quick'n'dirty method is to set the
this.ExitCode
to a non-zero value specifying what the Win32 error was and then call thethis.Stop()
method.A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
There's various ways of doing it, with equally various opinions on what's appropriate. The quick'n'dirty method is to set the
this.ExitCode
to a non-zero value specifying what the Win32 error was and then call thethis.Stop()
method.A guide to posting questions on CodeProject[^]
Dave Kreskowiak