Aracılığıyla paylaş


RunWorkerCompletedEventArgs Sınıf

Tanım

MethodNameCompleted olayı için veri sağlar.

public ref class RunWorkerCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class RunWorkerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type RunWorkerCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class RunWorkerCompletedEventArgs
Inherits AsyncCompletedEventArgs
Devralma
RunWorkerCompletedEventArgs

Örnekler

Aşağıdaki kod örneğinde kullanımı gösterilmektedir RunWorkerCompletedEventArgs. Bu örnek, sınıfı için BackgroundWorker daha büyük bir örneğin parçasıdır.

// This event handler deals with the results of the
// background operation.
void backgroundWorker1_RunWorkerCompleted( Object^ /*sender*/, RunWorkerCompletedEventArgs^ e )
{
   // First, handle the case where an exception was thrown.
   if ( e->Error != nullptr )
   {
      MessageBox::Show( e->Error->Message );
   }
   else
   if ( e->Cancelled )
   {
      // Next, handle the case where the user cancelled 
      // the operation.
      // Note that due to a race condition in 
      // the DoWork event handler, the Cancelled
      // flag may not have been set, even though
      // CancelAsync was called.
      resultLabel->Text = "Cancelled";
   }
   else
   {
      // Finally, handle the case where the operation 
      // succeeded.
      resultLabel->Text = e->Result->ToString();
   }

   // Enable the UpDown control.
   this->numericUpDown1->Enabled = true;

   // Enable the Start button.
   startAsyncButton->Enabled = true;

   // Disable the Cancel button.
   cancelAsyncButton->Enabled = false;
}
// This event handler deals with the results of the
// background operation.
void backgroundWorker1_RunWorkerCompleted(
    object sender, RunWorkerCompletedEventArgs e)
{
    // First, handle the case where an exception was thrown.
    if (e.Error != null)
    {
        _ = MessageBox.Show(e.Error.Message);
    }
    else if (e.Cancelled)
    {
        // Next, handle the case where the user canceled 
        // the operation.
        // Note that due to a race condition in 
        // the DoWork event handler, the Cancelled
        // flag may not have been set, even though
        // CancelAsync was called.
        resultLabel.Text = "Canceled";
    }
    else
    {
        // Finally, handle the case where the operation 
        // succeeded.
        resultLabel.Text = e.Result.ToString();
    }

    // Enable the UpDown control.
    numericUpDown1.Enabled = true;

    // Enable the Start button.
    startAsyncButton.Enabled = true;

    // Disable the Cancel button.
    cancelAsyncButton.Enabled = false;
}
' This event handler deals with the results of the
' background operation.
Private Sub backgroundWorker1_RunWorkerCompleted(
ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) _
Handles backgroundWorker1.RunWorkerCompleted

    ' First, handle the case where an exception was thrown.
    If (e.Error IsNot Nothing) Then
        MessageBox.Show(e.Error.Message)
    ElseIf e.Cancelled Then
        ' Next, handle the case where the user canceled the 
        ' operation.
        ' Note that due to a race condition in 
        ' the DoWork event handler, the Cancelled
        ' flag may not have been set, even though
        ' CancelAsync was called.
        resultLabel.Text = "Canceled"
    Else
        ' Finally, handle the case where the operation succeeded.
        resultLabel.Text = e.Result.ToString()
    End If

    ' Enable the UpDown control.
    numericUpDown1.Enabled = True

    ' Enable the Start button.
    startAsyncButton.Enabled = True

    ' Disable the Cancel button.
    cancelAsyncButton.Enabled = False
End Sub

Açıklamalar

Zaman uyumsuz işlemler için olay tabanlı zaman uyumsuz deseni kullanırken, Windows Forms formu veya denetimi yöntemini çağırarak BackgroundWorker.RunWorkerAsync zaman uyumsuz bir işlem başlatır. Yöntemi de olayı zaman uyumsuz olarak yükseltir BackgroundWorker.DoWork ve bir DoWorkEventArgs örnek iletir. Zaman uyumsuz işlem bir değer döndürürse, BackgroundWorker.DoWork olay işleyicisi genellikle bunu özelliğine DoWorkEventArgs.Result atar. Zaman uyumsuz işlem tamamlandığında, BackgroundWorker.RunWorkerCompleted olay oluşturulur ve işlemin durumu (iptal edildi, hatalı veya başarıyla tamamlandı) hakkında bilgi içeren bir RunWorkerCompletedEventArgs örnek geçirilir. Başarıyla tamamlanırsa, Result özelliği zaman uyumsuz işlem tarafından döndürülen ve daha önce özelliğine DoWorkEventArgs.Result atanan değeri içerir.

Uyarı

Bu HostProtectionAttribute sınıfa uygulanan öznitelik şu Resources özellik değerine sahiptir: SharedState. HostProtectionAttribute masaüstü uygulamalarını etkilemez (genellikle bir simgeye çift tıklayarak, komut yazarak veya bir tarayıcıya URL girerek başlatılır). Daha fazla bilgi için bkz HostProtectionAttribute . sınıf veya SQL Server Programlama ve Konak Koruması Öznitelikleri.

Oluşturucular

Name Description
RunWorkerCompletedEventArgs(Object, Exception, Boolean)

RunWorkerCompletedEventArgs sınıfının yeni bir örneğini başlatır.

Özellikler

Name Description
Cancelled

Zaman uyumsuz bir işlemin iptal edilip edilmediğini gösteren bir değer alır.

(Devralındığı yer: AsyncCompletedEventArgs)
Error

Zaman uyumsuz bir işlem sırasında hangi hatanın oluştuğunu belirten bir değer alır.

(Devralındığı yer: AsyncCompletedEventArgs)
Result

Zaman uyumsuz işlemin sonucunu temsil eden bir değer alır.

UserState

Kullanıcı durumunu temsil eden bir değer alır.

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
RaiseExceptionIfNecessary()

Zaman uyumsuz bir işlem başarısız olursa kullanıcı tarafından sağlanan bir özel durum oluşturur.

(Devralındığı yer: AsyncCompletedEventArgs)
ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.