Windows Server 2003およびWindows XPで作成したサービスを遅らせる方法
-
21-12-2019 - |
質問
私は何日前にサービス(winserviceproject)を作りました、そして、これが自動的に起動したが遅れた時間で...私は解決策を見つけました、しかし、これは私を助けることができました:
HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \ Services \ winserviceProjectでregeditを変更しますが、これは機能しません。
マルチ文字列値(依存セバイス)を追加し、以前に多くのサービスを設定します...これは機能しますが、欲しいのは好きではありません。
解決策私は時間がかかり、何度も設定してサービスを実行する必要があります。私のサービスにコードを追加する必要があるならば、私はそれをやるでしょう。
ありがとう。
解決
このコードで問題を解決します!!
パブリック静的void RestartService(String ServiceName、int TimeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
int millisec1 = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
// count the rest of the timeout
//int millisec2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - millisec1);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
// ...
}
}
. 所属していません StackOverflow