ServiceController.WaitForStatus Yöntem

Tanım

Hizmetin belirtilen duruma ulaşmasını bekler.

Aşırı Yüklemeler

WaitForStatus(ServiceControllerStatus)

Hizmetin belirtilen duruma ulaşmasını sonsuz olarak bekler.

WaitForStatus(ServiceControllerStatus, TimeSpan)

Hizmetin belirtilen duruma ulaşmasını veya belirtilen zaman aşımının süresinin dolmasını bekler.

WaitForStatus(ServiceControllerStatus)

Kaynak:
ServiceController.cs
Kaynak:
ServiceController.cs
Kaynak:
ServiceController.cs
Kaynak:
ServiceController.cs

Hizmetin belirtilen duruma ulaşmasını sonsuz olarak bekler.

public:
 void WaitForStatus(System::ServiceProcess::ServiceControllerStatus desiredStatus);
public void WaitForStatus (System.ServiceProcess.ServiceControllerStatus desiredStatus);
member this.WaitForStatus : System.ServiceProcess.ServiceControllerStatus -> unit
Public Sub WaitForStatus (desiredStatus As ServiceControllerStatus)

Parametreler

desiredStatus
ServiceControllerStatus

Beklenecek durum.

Özel durumlar

desiredStatus parametresi, numaralandırmada ServiceControllerStatus tanımlanan değerlerden herhangi biri değildir.

Örnekler

Aşağıdaki örnek, UyarıYıcı hizmetinin durdurulup durdurulmadığını denetlemek için sınıfını kullanır ServiceController . Hizmet durdurulursa, örnek hizmeti başlatır ve hizmet durumu olarak ayarlanana Runningkadar bekler.

// Check whether the Alerter service is started.
ServiceController^ sc = gcnew ServiceController;
if ( sc )
{
   sc->ServiceName =  "Alerter";
   Console::WriteLine(  "The Alerter service status is currently set to {0}", sc->Status );
   if ( sc->Status == (ServiceControllerStatus::Stopped) )
   {
      // Start the service if the current status is stopped.
      Console::WriteLine(  "Starting the Alerter service..." );
      try
      {
         // Start the service, and wait until its status is "Running".
         sc->Start();
         sc->WaitForStatus( ServiceControllerStatus::Running );
         
         // Display the current service status.
         Console::WriteLine(  "The Alerter service status is now set to {0}.", sc->Status );
      }
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine(  "Could not start the Alerter service." );
      }
   }
}

// Check whether the Alerter service is started.

ServiceController sc  = new ServiceController();
sc.ServiceName = "Alerter";
Console.WriteLine("The Alerter service status is currently set to {0}",
                   sc.Status);

if (sc.Status == ServiceControllerStatus.Stopped)
{
   // Start the service if the current status is stopped.

   Console.WriteLine("Starting the Alerter service...");
   try
   {
      // Start the service, and wait until its status is "Running".
      sc.Start();
      sc.WaitForStatus(ServiceControllerStatus.Running);

      // Display the current service status.
      Console.WriteLine("The Alerter service status is now set to {0}.",
                         sc.Status);
   }
   catch (InvalidOperationException)
   {
      Console.WriteLine("Could not start the Alerter service.");
   }
}

' Check whether the Alerter service is started.

Dim sc As New ServiceController()
sc.ServiceName = "Alerter"
Console.WriteLine("The Alerter service status is currently set to {0}", sc.Status)

If sc.Status = ServiceControllerStatus.Stopped Then
   ' Start the service if the current status is stopped.
   Console.WriteLine("Starting the Alerter service...")

   Try
      ' Start the service, and wait until its status is "Running".
      sc.Start()
      sc.WaitForStatus(ServiceControllerStatus.Running)
      
      ' Display the current service status.
      Console.WriteLine("The Alerter service status is now set to {0}.", sc.Status)
   Catch 
      Console.WriteLine("Could not start the Alerter service.")
   End Try
End If

Açıklamalar

Hizmet gerekli duruma ulaşana kadar uygulamanın işlemesini askıya almak için kullanın WaitForStatus .

Not

yöntemi her WaitForStatus durum denetimi arasında yaklaşık 250 milisaniye bekler. WaitForStatus , gözlemlenen hizmetin söz konusu aralıkta ve sonra hemen başka bir duruma değiştiğini desiredStatus algılayamaz.

Ayrıca bkz.

Şunlara uygulanır

WaitForStatus(ServiceControllerStatus, TimeSpan)

Kaynak:
ServiceController.cs
Kaynak:
ServiceController.cs
Kaynak:
ServiceController.cs
Kaynak:
ServiceController.cs

Hizmetin belirtilen duruma ulaşmasını veya belirtilen zaman aşımının süresinin dolmasını bekler.

public:
 void WaitForStatus(System::ServiceProcess::ServiceControllerStatus desiredStatus, TimeSpan timeout);
public void WaitForStatus (System.ServiceProcess.ServiceControllerStatus desiredStatus, TimeSpan timeout);
member this.WaitForStatus : System.ServiceProcess.ServiceControllerStatus * TimeSpan -> unit
Public Sub WaitForStatus (desiredStatus As ServiceControllerStatus, timeout As TimeSpan)

Parametreler

desiredStatus
ServiceControllerStatus

Beklenecek durum.

timeout
TimeSpan

TimeSpan Hizmetin belirtilen duruma ulaşması için beklenmesi gereken süreyi belirten nesne.

Özel durumlar

desiredStatus parametresi, numaralandırmada ServiceControllerStatus tanımlanan değerlerden herhangi biri değildir.

parametresi için belirtilen değerin timeout süresi dolar.

Açıklamalar

Hizmet gerekli duruma ulaşana kadar uygulamanın işlemesini askıya almak için kullanın WaitForStatus .

Not

yöntemi her WaitForStatus durum denetimi arasında yaklaşık 250 milisaniye bekler. WaitForStatus , gözlemlenen hizmetin söz konusu aralıkta ve sonra hemen başka bir duruma değiştiğini desiredStatus algılayamaz.

Ayrıca bkz.

Şunlara uygulanır