这是我所说的:
protected override void OnStart(string[] args)
{
if (SomeApp.Initialize())
{
SomeApp.StartMonitorAndWork();
base.OnStart(args);
}
}
protected override void OnStop()
{
SomeApp.TearDown();
base.OnStop();
}
这里,如果STOP! 如果会议开始:
Timer(new TimerCallback(DoWork), null, startTime, loopTime);
和 定期调查数据库。
如果开端失败(核对记录),我试图停止从行政工具及服务中提供服务:
Could not stop the SomeService on Local Computer. The service did not return an error. This could be internal Windows error or an internal service error. If the problem persists, contact system administrator.
The question is: "Is exiting OnStart without doing nothing enough if Initialize returns false?
还是应该这样:
private void ExitService()
{
this.OnStop();
System.Environment.Exit(1);
}
protected override void OnStart(string[] args)
{
if (ObjectFolderApp.Initialize())
{
SomeApp.StartMonitorAndWork();
base.OnStart(args);
}
else
{
ExitService();
}
}
附录
EDIT: I came up with something like this:
protected override void OnStart(string[] args)
{
try
{
if (SomeApp.Initialize())
{
SomeApp.StartMonitorAndWork();
base.OnStart(args);
}
else
{
Stop();
}
}
catch
{
Stop();
}
}
protected override void OnStop()
{
try
{
SomeApp.TearDown();
base.OnStop();
}
catch
{
base.OnStop();
}
}