本文整理汇总了C#中ServiceController.WaitForStatus方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceController.WaitForStatus方法的具体用法?C# ServiceController.WaitForStatus怎么用?C# ServiceController.WaitForStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceController
的用法示例。
在下文中一共展示了ServiceController.WaitForStatus方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WaitForStatusTimeout
public void WaitForStatusTimeout()
{
var controller = new ServiceController(_testService.TestServiceName);
Assert.Throws<System.ServiceProcess.TimeoutException>(() => controller.WaitForStatus(ServiceControllerStatus.Paused, TimeSpan.Zero));
}
示例2: StopAndStart
public void StopAndStart()
{
var controller = new ServiceController(_testService.TestServiceName);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
for (int i = 0; i < 2; i++)
{
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);
controller.Start();
controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
}
}
示例3: PauseAndContinue
public void PauseAndContinue()
{
var controller = new ServiceController(_testService.TestServiceName);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
for (int i = 0; i < 2; i++)
{
controller.Pause();
controller.WaitForStatus(ServiceControllerStatus.Paused, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Paused, controller.Status);
controller.Continue();
controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
}
}
示例4: StartWithArguments
public void StartWithArguments()
{
var controller = new ServiceController(_testService.TestServiceName);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);
var args = new[] { "a", "b", "c", "d", "e" };
controller.Start(args);
controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
// The test service writes the arguments that it was started with to the _testService.TestServiceRegistryKey.
// Read this key to verify that the arguments were properly passed to the service.
string argsString = Registry.GetValue(_testService.TestServiceRegistryKey, "ServiceArguments", null) as string;
Assert.Equal(string.Join(",", args), argsString);
}
示例5: Main
//.........这里部分代码省略.........
{
Log.Debug("Main: Failed to retrieve TV service status");
ctrl.Close();
ctrl = null;
}
}
if (ctrl != null)
{
Log.Debug("Main: TV service found. Checking status...");
UpdateSplashScreenMessage(GUILocalizeStrings.Get(60)); // Waiting for startup of TV service...
if (ctrl.Status == ServiceControllerStatus.StartPending || ctrl.Status == ServiceControllerStatus.Stopped)
{
if (ctrl.Status == ServiceControllerStatus.StartPending)
{
Log.Info("Main: TV service start is pending. Waiting...");
}
if (ctrl.Status == ServiceControllerStatus.Stopped)
{
Log.Info("Main: TV service is stopped, so we try start it...");
try
{
ctrl.Start();
}
catch (Exception)
{
Log.Info("TvService seems to be already starting up.");
}
}
try
{
ctrl.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 45));
}
// ReSharper disable EmptyGeneralCatchClause
catch (Exception) {}
// ReSharper restore EmptyGeneralCatchClause
if (ctrl.Status == ServiceControllerStatus.Running)
{
Log.Info("Main: The TV service has started successfully.");
}
else
{
Log.Info("Main: Startup of the TV service failed - current status: {0}", ctrl.Status.ToString());
}
}
Log.Info("Main: TV service is in status {0} - proceeding...", ctrl.Status.ToString());
ctrl.Close();
}
}
Application.DoEvents(); // process message queue
if (_startupDelay > 0)
{
Log.Info("Main: Waiting {0} second(s) before startup", _startupDelay);
for (int i = _startupDelay; i > 0; i--)
{
UpdateSplashScreenMessage(String.Format(GUILocalizeStrings.Get(61), i.ToString(CultureInfo.InvariantCulture)));
Thread.Sleep(1000);
Application.DoEvents();
}
}
示例6: Main
//.........这里部分代码省略.........
}
catch (Exception)
{
ctrl = null;
Log.Debug("Main: TV service not installed - proceeding...");
}
if (ctrl != null)
{
Log.Debug("Main: TV service found. Checking status...");
if (splashScreen != null)
{
splashScreen.SetInformation(GUILocalizeStrings.Get(60)); // Waiting for startup of TV service...
}
if (ctrl.Status == ServiceControllerStatus.StartPending || ctrl.Status == ServiceControllerStatus.Stopped)
{
if (ctrl.Status == ServiceControllerStatus.StartPending)
{
Log.Info("Main: TV service start is pending. Waiting...");
}
if (ctrl.Status == ServiceControllerStatus.Stopped)
{
Log.Info("Main: TV service is stopped, so we try start it...");
try
{
ctrl.Start();
}
catch (Exception)
{
Log.Info("TvService seems to be already starting up.");
}
}
try
{
ctrl.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 45));
}
catch (Exception) {}
if (ctrl.Status == ServiceControllerStatus.Running)
{
Log.Info("Main: The TV service has started successfully.");
}
else
{
Log.Info("Main: Startup of the TV service failed - current status: {0}", ctrl.Status.ToString());
}
}
Log.Info("Main: TV service is in status {0} - proceeding...", ctrl.Status.ToString());
ctrl.Close();
}
}
Application.DoEvents();
if (_startupDelay > 0)
{
Log.Info("Main: Waiting {0} second(s) before startup", _startupDelay);
for (int i = _startupDelay; i > 0; i--)
{
if (splashScreen != null)
{
splashScreen.SetInformation(String.Format(GUILocalizeStrings.Get(61), i.ToString()));
// Waiting {0} second(s) before startup...
}
Application.DoEvents();
Thread.Sleep(1000);
}
}
Log.Debug("Main: Checking prerequisites");
try
示例7: RestartC2RSerivce
public static void RestartC2RSerivce()
{
const string serviceName = "ClickToRunSvc";
var service = new ServiceController(serviceName);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 5));
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 5));
}
示例8: ControlCapabilities
public void ControlCapabilities()
{
var controller = new ServiceController(_testService.TestServiceName);
controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
Assert.True(controller.CanStop);
Assert.True(controller.CanPauseAndContinue);
Assert.False(controller.CanShutdown);
}