ServiceController.WaitForStatus Metode

Definisi

Menunggu layanan mencapai status yang ditentukan.

Overload

Nama Deskripsi
WaitForStatus(ServiceControllerStatus)

Tak terbatas menunggu layanan mencapai status yang ditentukan.

WaitForStatus(ServiceControllerStatus, TimeSpan)

Menunggu layanan mencapai status yang ditentukan atau waktu habis yang ditentukan kedaluwarsa.

WaitForStatus(ServiceControllerStatus)

Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs

Tak terbatas menunggu layanan mencapai status yang ditentukan.

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)

Parameter

desiredStatus
ServiceControllerStatus

Status untuk menunggu.

Pengecualian

Parameter desiredStatus bukan salah satu nilai yang ditentukan dalam ServiceControllerStatus enumerasi.

Contoh

Contoh berikut menggunakan ServiceController kelas untuk memeriksa apakah layanan Pemberitahuan dihentikan. Jika layanan dihentikan, contoh memulai layanan dan menunggu hingga status layanan diatur ke Running.

// 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

Keterangan

Gunakan WaitForStatus untuk menangguhkan pemrosesan aplikasi hingga layanan mencapai status yang diperlukan.

Note

Metode ini WaitForStatus menunggu sekitar 250 milidetik di antara setiap pemeriksaan status. WaitForStatus tidak dapat mendeteksi kasus layanan yang diamati berubah ke desiredStatus dan kemudian segera ke status lain dalam interval tersebut.

Lihat juga

Berlaku untuk

WaitForStatus(ServiceControllerStatus, TimeSpan)

Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs

Menunggu layanan mencapai status yang ditentukan atau waktu habis yang ditentukan kedaluwarsa.

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)

Parameter

desiredStatus
ServiceControllerStatus

Status untuk menunggu.

timeout
TimeSpan

Objek TimeSpan yang menentukan jumlah waktu untuk menunggu layanan mencapai status yang ditentukan.

Pengecualian

Parameter desiredStatus bukan salah satu nilai yang ditentukan dalam ServiceControllerStatus enumerasi.

Nilai yang ditentukan untuk parameter kedaluwarsa timeout .

Keterangan

Gunakan WaitForStatus untuk menangguhkan pemrosesan aplikasi hingga layanan mencapai status yang diperlukan.

Note

Metode ini WaitForStatus menunggu sekitar 250 milidetik di antara setiap pemeriksaan status. WaitForStatus tidak dapat mendeteksi kasus layanan yang diamati berubah ke desiredStatus dan kemudian segera ke status lain dalam interval tersebut.

Lihat juga

Berlaku untuk