Well I did exactly what you said, commenting out all the code in my OnStart,
threw an exception, looked in the SMC and it still shows as running... I can
even press the start and stop buttons in the SMC, and it stops and starts
with no problem...
Here's the OnStart code... as I said, it does nothing but throw the
exception:
protected override void OnStart(string[] args)
{
throw(new Exception("Service failed to start"));
// this.oAppSettings.ListenPort =
Convert.ToInt32(ConfigurationSettings.AppSettings["ListenPort"].ToString());
// this.oAppSettings.LogPath =
ConfigurationSettings.AppSettings["LogPath"].ToString();
// this.oAppSettings.TestPath =
ConfigurationSettings.AppSettings["TestPath"].ToString();
// this.oAppSettings.ConnectionTimeout =
Convert.ToInt32(ConfigurationSettings.AppSettings["ConnectionTimeout"].ToString());
// this.oAppSettings.DataDSN =
ConfigurationSettings.AppSettings["DataDSN"].ToString();
// this.oAppSettings.ShowGreeting =
Convert.ToBoolean(ConfigurationSettings.AppSetting s["ShowGreeting"].ToString());
// this.oAppSettings.GlobalParse =
Convert.ToBoolean(ConfigurationSettings.AppSetting s["GlobalParse"].ToString());
// this.oAppSettings.OnCustomParse =
ConfigurationSettings.AppSettings["OnCustomParse"].ToString();
// this.oAppSettings.OnResponse =
ConfigurationSettings.AppSettings["OnResponse"].ToString();
//
// if((this.oAppSettings.LogPath != "") &&
!this.oAppSettings.LogPath.EndsWith("\\"))
// {
// this.oAppSettings.LogPath += "\\";
// }
//
// if((this.oAppSettings.TestPath != "") &&
!this.oAppSettings.TestPath.EndsWith("\\"))
// {
// this.oAppSettings.TestPath += "\\";
// }
//
// if(this.oAppSettings.ConnectionTimeout > 0)
// {
// this.oAppSettings.ConnectionTimeout *= (1000 * 60);
// }
//
// // TODO add appropriate validation for config settings
// // TODO throwing an exception here should cause the OnStart to fail...
// // throw(new Exception("Service failed to start... config errors"));
//
// WMI_StatusProvider.FireEvent("GSRouter Service Started", "GSRouter",
EventType.ServiceStart);
// this.sockServer.Listen(this.oAppSettings.ListenPor t);
// this.dtUpTime = DateTime.Now;
}
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Should work for you as well, try to remove all code there is in OnStart
and leave the throw clause. If this doesn't work either post your code
(OnStart).
Willy.
"JSheble" <js************@logicor.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl... That's exactly what I have in the code, but the service still shows as
running in the SMC...
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
"JSheble" <js************@logicor.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Is there anything special I should know about this? I tried throwing
an exception in my OnStart, but the service still shows as running in
the SMC... Is there something else that has to occur besides just
throwing an exception? Is there a certain type of exception I should
throw?
protected override void OnStart(string[] args)
{
...
// throw whatever Exception
throw (new Exception("Service failed to init..."));
...
Make sure you don't catch the exception, the service should stop and
automatically write a stack trace to the "Application" eventlog.
Willy.