Exemplarische Vorgehensweise: Implementieren eines Formulars, das eine Hintergrundoperation verwendet

Wenn die Ausführung einer Operation sehr lange dauert und Sie verhindern möchten, dass die Benutzeroberfläche (UI) nicht mehr reagiert oder sich "aufhängt", können Sie mit der BackgroundWorker-Klasse die Operation mit einem anderen Thread ausführen.

Diese exemplarische Vorgehensweise veranschaulicht, wie die BackgroundWorker-Klasse zur Durchführung zeitintensiver Berechnungen "im Hintergrund" verwendet wird, während die Benutzeroberfläche weiterhin reagiert. Anschließend verfügen Sie über eine Anwendung, die Fibonacci-Zahlen asynchron berechnet. Auch wenn die Berechnung einer großen Fibonacci-Zahl recht lange dauern kann, wird der primäre UI-Thread von dieser Verzögerung nicht unterbrochen, sodass das Formular auch während der Berechnung auf Eingaben reagiert.

Zu den Aufgaben in dieser exemplarischen Vorgehensweise gehören:

  • Erstellen einer Windows-basierten Anwendung

  • Erstellen eines BackgroundWorker im Formular

  • Hinzufügen von asynchronen Ereignishandlern

  • Hinzufügen von Fortschrittsberichterstellung und Abbruchunterstützung

Eine vollständige Liste des in diesem Beispiel verwendeten Codes finden Sie unter Gewusst wie: Implementieren eines Formulars, das eine Hintergrundoperation verwendet.

Tipp

Je nach den aktiven Einstellungen oder der Version unterscheiden sich die Dialogfelder und Menübefehle auf Ihrem Bildschirm möglicherweise von den in der Hilfe beschriebenen. Klicken Sie im Menü Extras auf Einstellungen importieren und exportieren, um die Einstellungen zu ändern. Weitere Informationen finden Sie unter Arbeiten mit Einstellungen.

Erstellen des Projekts

Zunächst wird das Projekt erstellt und das Formular eingerichtet.

So erstellen Sie ein Formular, das eine Hintergrundoperation verwendet

  1. Erstellen Sie ein Windows-basiertes Anwendungsprojekt mit dem Namen BackgroundWorkerExample. Ausführliche Informationen finden Sie unter Gewusst wie: Erstellen eines neuen Windows Forms-Anwendungsprojekts.

  2. Klicken Sie im Projektmappen-Explorer mit der rechten Maustaste auf Form1 und dann im Kontextmenü auf Umbenennen. Ändern Sie den Dateinamen in FibonacciCalculator. Klicken Sie auf die Schaltfläche Ja, wenn Sie gefragt werden, ob Sie alle Verweise auf das Codeelement 'Form1' umbenennen möchten.

  3. Ziehen Sie ein NumericUpDown-Steuerelement aus der Toolbox auf das Formular. Legen Sie die Minimum-Eigenschaft auf 1 und die Maximum-Eigenschaft auf 91 fest.

  4. Fügen Sie dem Formular zwei Button-Steuerelemente hinzu.

  5. Benennen Sie das erste Button-Steuerelement in startAsyncButton um, und legen Sie die Text-Eigenschaft auf Start Async fest. Benennen Sie das zweite Button-Steuerelement in cancelAsyncButton um, und legen Sie die Text-Eigenschaft auf Cancel Async fest. Legen Sie die entsprechende Enabled-Eigenschaft auf false fest.

  6. Erstellen Sie einen Ereignishandler für beide Click-Ereignisse des Button-Steuerelements. Ausführliche Informationen finden Sie unter Gewusst wie: Erstellen von Ereignishandlern mithilfe des Designers.

  7. Ziehen Sie ein Label-Steuerelement aus der Toolbox auf das Formular, und benennen Sie es in resultLabel um.

  8. Ziehen Sie ein ProgressBar-Steuerelement aus der Toolbox auf das Formular.

Erstellen eines BackgroundWorker im Formular

Sie können den BackgroundWorker für die asynchrone Operation mit dem Windows Forms-Designer erstellen.

So erstellen Sie einen BackgroundWorker mithilfe des Designers

  • Ziehen Sie von der Registerkarte Komponenten der Toolbox einen BackgroundWorker auf das Formular.

Hinzufügen von asynchronen Ereignishandlern

Sie sind nun bereit, Ereignishandler für die asynchronen Ereignisse der BackgroundWorker-Komponente hinzuzufügen. Die zeitintensive Operation, die im Hintergrund ausgeführt wird und Fibonacci-Zahlen berechnet, wird von einem dieser Ereignishandler aufgerufen.

So implementieren Sie asynchrone Ereignishandler

  1. Klicken Sie im Eigenschaftenfenster bei ausgewählter BackgroundWorker-Komponente auf die Schaltfläche Ereignisse. Doppelklicken Sie auf das DoWork-Ereignis und das RunWorkerCompleted-Ereignis, um Ereignishandler zu erstellen. Weitere Informationen zur Verwendung von Ereignishandlern finden Sie unter Gewusst wie: Erstellen von Ereignishandlern mithilfe des Designers.

  2. Erstellen Sie im Formular eine neue Methode mit dem Namen ComputeFibonacci. Diese Methode erledigt die eigentliche Arbeit und wird im Hintergrund ausgeführt. Dieser Code veranschaulicht die rekursive Umsetzung des Fibonacci-Algorithmus, der deutlich ineffizient und bei großen Zahlen exponentiell langsamer ist. Er wird hier verwendet, um eine Operation zu zeigen, die Ihre Anwendung deutlich verlangsamen kann.

    ' This is the method that does the actual work. For this
    ' example, it computes a Fibonacci number and
    ' reports progress as it does its work.
    Function ComputeFibonacci( _
        ByVal n As Integer, _
        ByVal worker As BackgroundWorker, _
        ByVal e As DoWorkEventArgs) As Long
    
        ' The parameter n must be >= 0 and <= 91.
        ' Fib(n), with n > 91, overflows a long.
        If n < 0 OrElse n > 91 Then
            Throw New ArgumentException( _
                "value must be >= 0 and <= 91", "n")
        End If
    
        Dim result As Long = 0
    
        ' Abort the operation if the user has canceled.
        ' Note that a call to CancelAsync may have set 
        ' CancellationPending to true just after the
        ' last invocation of this method exits, so this 
        ' code will not have the opportunity to set the 
        ' DoWorkEventArgs.Cancel flag to true. This means
        ' that RunWorkerCompletedEventArgs.Cancelled will
        ' not be set to true in your RunWorkerCompleted
        ' event handler. This is a race condition.
        If worker.CancellationPending Then
            e.Cancel = True
        Else
            If n < 2 Then
                result = 1
            Else
                result = ComputeFibonacci(n - 1, worker, e) + _
                         ComputeFibonacci(n - 2, worker, e)
            End If
    
            ' Report progress as a percentage of the total task.
            Dim percentComplete As Integer = _
                CSng(n) / CSng(numberToCompute) * 100
            If percentComplete > highestPercentageReached Then
                highestPercentageReached = percentComplete
                worker.ReportProgress(percentComplete)
            End If
    
        End If
    
        Return result
    
    End Function
    
    // This is the method that does the actual work. For this
    // example, it computes a Fibonacci number and
    // reports progress as it does its work.
    long ComputeFibonacci(int n, BackgroundWorker worker, DoWorkEventArgs e)
    {
        // The parameter n must be >= 0 and <= 91.
        // Fib(n), with n > 91, overflows a long.
        if ((n < 0) || (n > 91))
        {
            throw new ArgumentException(
                "value must be >= 0 and <= 91", "n");
        }
    
        long result = 0;
    
        // Abort the operation if the user has canceled.
        // Note that a call to CancelAsync may have set 
        // CancellationPending to true just after the
        // last invocation of this method exits, so this 
        // code will not have the opportunity to set the 
        // DoWorkEventArgs.Cancel flag to true. This means
        // that RunWorkerCompletedEventArgs.Cancelled will
        // not be set to true in your RunWorkerCompleted
        // event handler. This is a race condition.
    
        if (worker.CancellationPending)
        {   
            e.Cancel = true;
        }
        else
        {   
            if (n < 2)
            {   
                result = 1;
            }
            else
            {   
                result = ComputeFibonacci(n - 1, worker, e) + 
                         ComputeFibonacci(n - 2, worker, e);
            }
    
            // Report progress as a percentage of the total task.
            int percentComplete = 
                (int)((float)n / (float)numberToCompute * 100);
            if (percentComplete > highestPercentageReached)
            {
                highestPercentageReached = percentComplete;
                worker.ReportProgress(percentComplete);
            }
        }
    
        return result;
    }
    
    // This is the method that does the actual work. For this
    // example, it computes a Fibonacci number and
    // reports progress as it does its work.
    long ComputeFibonacci( int n, BackgroundWorker^ worker, DoWorkEventArgs ^ e )
    {
       // The parameter n must be >= 0 and <= 91.
       // Fib(n), with n > 91, overflows a long.
       if ( (n < 0) || (n > 91) )
       {
          throw gcnew ArgumentException( "value must be >= 0 and <= 91","n" );
       }
    
       long result = 0;
    
       // Abort the operation if the user has cancelled.
       // Note that a call to CancelAsync may have set 
       // CancellationPending to true just after the
       // last invocation of this method exits, so this 
       // code will not have the opportunity to set the 
       // DoWorkEventArgs.Cancel flag to true. This means
       // that RunWorkerCompletedEventArgs.Cancelled will
       // not be set to true in your RunWorkerCompleted
       // event handler. This is a race condition.
       if ( worker->CancellationPending )
       {
          e->Cancel = true;
       }
       else
       {
          if ( n < 2 )
          {
             result = 1;
          }
          else
          {
             result = ComputeFibonacci( n - 1, worker, e ) + ComputeFibonacci( n - 2, worker, e );
          }
    
          // Report progress as a percentage of the total task.
          int percentComplete = (int)((float)n / (float)numberToCompute * 100);
          if ( percentComplete > highestPercentageReached )
          {
             highestPercentageReached = percentComplete;
             worker->ReportProgress( percentComplete );
          }
       }
    
       return result;
    }
    
  3. Fügen Sie im DoWork-Ereignishandler der ComputeFibonacci-Methode einen Aufruf hinzu. Übernehmen Sie den ersten Parameter für ComputeFibonacci von der Argument-Eigenschaft des DoWorkEventArgs. Der BackgroundWorker-Parameter und der DoWorkEventArgs-Parameter werden später zur Fortschrittsberichterstellung und Abbruchunterstützung verwendet. Weisen Sie der Result-Eigenschaft von DoWorkEventArgs den Rückgabewert von ComputeFibonacci zu. Dieses Ergebnis steht dem RunWorkerCompleted-Ereignishandler zur Verfügung.

    Tipp

    Der DoWork-Ereignishandler verweist nicht direkt auf die backgroundWorker1-Instanzvariable, da dieser Ereignishandler ansonsten mit einer spezifischen Instanz von BackgroundWorker gekoppelt wird. Stattdessen wird ein Verweis auf den BackgroundWorker, der dieses Ereignis ausgelöst hat, vom sender-Parameter wiederhergestellt. Dies ist wichtig, wenn das Formular mehr als einen BackgroundWorker hostet. Beachten Sie weiterhin, dass im DoWork-Ereignishandler keine Benutzeroberflächenobjekte bearbeitet werden dürfen. Verwenden Sie stattdessen zum Kommunizieren mit der Benutzeroberfläche die BackgroundWorker-Ereignisse.

    ' This event handler is where the actual work is done.
    Private Sub backgroundWorker1_DoWork( _
    ByVal sender As Object, _
    ByVal e As DoWorkEventArgs) _
    Handles backgroundWorker1.DoWork
    
        ' Get the BackgroundWorker object that raised this event.
        Dim worker As BackgroundWorker = _
            CType(sender, BackgroundWorker)
    
        ' Assign the result of the computation
        ' to the Result property of the DoWorkEventArgs
        ' object. This is will be available to the 
        ' RunWorkerCompleted eventhandler.
        e.Result = ComputeFibonacci(e.Argument, worker, e)
    End Sub 'backgroundWorker1_DoWork
    
    // This event handler is where the actual,
    // potentially time-consuming work is done.
    private void backgroundWorker1_DoWork(object sender, 
        DoWorkEventArgs e)
    {   
        // Get the BackgroundWorker that raised this event.
        BackgroundWorker worker = sender as BackgroundWorker;
    
        // Assign the result of the computation
        // to the Result property of the DoWorkEventArgs
        // object. This is will be available to the 
        // RunWorkerCompleted eventhandler.
        e.Result = ComputeFibonacci((int)e.Argument, worker, e);
    }
    
    // This event handler is where the actual,
    // potentially time-consuming work is done.
    void backgroundWorker1_DoWork( Object^ sender, DoWorkEventArgs^ e )
    {
       // Get the BackgroundWorker that raised this event.
       BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);
    
       // Assign the result of the computation
       // to the Result property of the DoWorkEventArgs
       // object. This is will be available to the 
       // RunWorkerCompleted eventhandler.
       e->Result = ComputeFibonacci( safe_cast<Int32>(e->Argument), worker, e );
    }
    
  4. Fügen Sie im Click-Ereignishandler des startAsyncButton-Steuerelements den Code hinzu, mit dem die asynchrone Operation gestartet wird.

    Private Sub startAsyncButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles startAsyncButton.Click
    
        ' Reset the text in the result label.
        resultLabel.Text = [String].Empty
    
        ' Disable the UpDown control until 
        ' the asynchronous operation is done.
        Me.numericUpDown1.Enabled = False
    
        ' Disable the Start button until 
        ' the asynchronous operation is done.
        Me.startAsyncButton.Enabled = False
    
        ' Enable the Cancel button while 
        ' the asynchronous operation runs.
        Me.cancelAsyncButton.Enabled = True
    
        ' Get the value from the UpDown control.
        numberToCompute = CInt(numericUpDown1.Value)
    
        ' Reset the variable for percentage tracking.
        highestPercentageReached = 0
    
    
        ' Start the asynchronous operation.
        backgroundWorker1.RunWorkerAsync(numberToCompute)
    End Sub 
    
    private void startAsyncButton_Click(System.Object sender, 
        System.EventArgs e)
    {
        // Reset the text in the result label.
        resultLabel.Text = String.Empty;
    
        // Disable the UpDown control until 
        // the asynchronous operation is done.
        this.numericUpDown1.Enabled = false;
    
        // Disable the Start button until 
        // the asynchronous operation is done.
        this.startAsyncButton.Enabled = false;
    
        // Enable the Cancel button while 
        // the asynchronous operation runs.
        this.cancelAsyncButton.Enabled = true;
    
        // Get the value from the UpDown control.
        numberToCompute = (int)numericUpDown1.Value;
    
        // Reset the variable for percentage tracking.
        highestPercentageReached = 0;
    
        // Start the asynchronous operation.
        backgroundWorker1.RunWorkerAsync(numberToCompute);
    }
    
    void startAsyncButton_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
    {
    
       // Reset the text in the result label.
       resultLabel->Text = String::Empty;
    
       // Disable the UpDown control until 
       // the asynchronous operation is done.
       this->numericUpDown1->Enabled = false;
    
       // Disable the Start button until 
       // the asynchronous operation is done.
       this->startAsyncButton->Enabled = false;
    
       // Enable the Cancel button while 
       // the asynchronous operation runs.
       this->cancelAsyncButton->Enabled = true;
    
       // Get the value from the UpDown control.
       numberToCompute = (int)numericUpDown1->Value;
    
       // Reset the variable for percentage tracking.
       highestPercentageReached = 0;
    
       // Start the asynchronous operation.
       backgroundWorker1->RunWorkerAsync( numberToCompute );
    }
    
  5. Weisen Sie im RunWorkerCompleted-Ereignishandler das Ergebnis der Berechnung dem resultLabel-Steuerelement zu.

    ' 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.
        Me.numericUpDown1.Enabled = True
    
        ' Enable the Start button.
        startAsyncButton.Enabled = True
    
        ' Disable the Cancel button.
        cancelAsyncButton.Enabled = False
    End Sub 'backgroundWorker1_RunWorkerCompleted
    
    // This event handler deals with the results of the
    // background operation.
    private 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.
        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 != 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;
    }
    

Hinzufügen von Fortschrittsberichterstellung und Abbruchunterstützung

Bei asynchronen Operationen, die lange dauern, ist es häufig wünschenswert, dem Benutzer den Fortschritt mitzuteilen und es ihm zu ermöglichen, die Operation abzubrechen. Die BackgroundWorker-Klasse stellt ein Ereignis bereit, mit dem Sie den Fortschritt aufzeichnen können, während die Operation im Hintergrund ausgeführt wird. Darüber hinaus verfügt sie über ein Flag, mit dem der Workercode einen Aufruf an CancelAsync erkennen und sich selbst unterbrechen kann.

So implementieren Sie die Fortschrittsberichterstellung

  1. Wählen Sie im Eigenschaftenfenster backgroundWorker1 aus. Legen Sie die WorkerReportsProgress-Eigenschaft und die WorkerSupportsCancellation-Eigenschaft auf true fest.

  2. Deklarieren Sie zwei Variablen im FibonacciCalculator-Formular. Diese werden verwendet, um den Fortschritt zu verfolgen.

    Private numberToCompute As Integer = 0
    Private highestPercentageReached As Integer = 0
    
    private int numberToCompute = 0;
    private int highestPercentageReached = 0;
    
    int numberToCompute;
    int highestPercentageReached;
    
  3. Fügen Sie einen Ereignishandler für das ProgressChanged-Ereignis hinzu. Aktualisieren Sie im ProgressChanged-Ereignishandler die ProgressBar mit der ProgressPercentage-Eigenschaft des ProgressChangedEventArgs-Parameters.

    ' This event handler updates the progress bar.
    Private Sub backgroundWorker1_ProgressChanged( _
    ByVal sender As Object, ByVal e As ProgressChangedEventArgs) _
    Handles backgroundWorker1.ProgressChanged
    
        Me.progressBar1.Value = e.ProgressPercentage
    
    End Sub
    
    // This event handler updates the progress bar.
    private void backgroundWorker1_ProgressChanged(object sender,
        ProgressChangedEventArgs e)
    {
        this.progressBar1.Value = e.ProgressPercentage;
    }
    
    // This event handler updates the progress bar.
    void backgroundWorker1_ProgressChanged( Object^ /*sender*/, ProgressChangedEventArgs^ e )
    {
       this->progressBar1->Value = e->ProgressPercentage;
    }
    

So implementieren Sie die Abbruchunterstützung

  1. Fügen Sie im Click-Ereignishandler des cancelAsyncButton-Steuerelements den Code hinzu, mit dem die asynchrone Operation abgebrochen wird.

    Private Sub cancelAsyncButton_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles cancelAsyncButton.Click
    
        ' Cancel the asynchronous operation.
        Me.backgroundWorker1.CancelAsync()
    
        ' Disable the Cancel button.
        cancelAsyncButton.Enabled = False
    
    End Sub 'cancelAsyncButton_Click
    
    private void cancelAsyncButton_Click(System.Object sender, 
        System.EventArgs e)
    {   
        // Cancel the asynchronous operation.
        this.backgroundWorker1.CancelAsync();
    
        // Disable the Cancel button.
        cancelAsyncButton.Enabled = false;
    }
    
    void cancelAsyncButton_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
    {  
       // Cancel the asynchronous operation.
       this->backgroundWorker1->CancelAsync();
    
       // Disable the Cancel button.
       cancelAsyncButton->Enabled = false;
    }
    
  2. Die folgenden Codefragmente in der ComputeFibonacci-Methode dienen zur Fortschrittsberichterstellung und Abbruchunterstützung.

    If worker.CancellationPending Then
        e.Cancel = True
    
    
    ...
    
    
    ' Report progress as a percentage of the total task.
    Dim percentComplete As Integer = _
        CSng(n) / CSng(numberToCompute) * 100
    If percentComplete > highestPercentageReached Then
        highestPercentageReached = percentComplete
        worker.ReportProgress(percentComplete)
    End If
    
    if (worker.CancellationPending)
    {   
        e.Cancel = true;
    }
    
    
    ...
    
    
    // Report progress as a percentage of the total task.
    int percentComplete = 
        (int)((float)n / (float)numberToCompute * 100);
    if (percentComplete > highestPercentageReached)
    {
        highestPercentageReached = percentComplete;
        worker.ReportProgress(percentComplete);
    }
    
    if ( worker->CancellationPending )
    {
       e->Cancel = true;
    }
    
    
    ...
    
    
    // Report progress as a percentage of the total task.
    int percentComplete = (int)((float)n / (float)numberToCompute * 100);
    if ( percentComplete > highestPercentageReached )
    {
       highestPercentageReached = percentComplete;
       worker->ReportProgress( percentComplete );
    }
    

Checkpoint

An diesem Punkt können Sie die Fibonacci-Berechnung kompilieren und ausführen.

So testen Sie das Projekt

  • Drücken Sie F5, um die Anwendung zu kompilieren und auszuführen.

    Während die Berechnung ausgeführt wird, wird in der ProgressBar der Fortschritt der Berechnung angezeigt. Sie können die anstehende Operation auch abbrechen.

    Bei kleinen Zahlen sollte die Berechnung sehr schnell gehen, während bei großen Zahlen eine deutliche Verzögerung erkennbar ist. Wenn Sie einen Wert von 30 oder höher eingeben, sollten Sie je nach Geschwindigkeit des Computers eine Verzögerung von mehreren Sekunden bemerken. Bei Werten über 40 dauert die Berechnung möglicherweise Minuten oder Stunden. Beachten Sie, dass Sie während der Berechnung einer großen Fibonacci-Zahl das Formular dennoch beliebig verschieben, minimieren, maximieren oder sogar schließen können. Der Grund dafür ist, dass der primäre UI-Thread nicht auf die Fertigstellung der Berechnung wartet.

Nächste Schritte

Nachdem Sie ein Formular implementiert haben, dass eine BackgroundWorker-Komponente für eine Berechnung im Hintergrund verwendet, können Sie weitere Möglichkeiten für asynchrone Operationen ausprobieren:

Siehe auch

Aufgaben

Gewusst wie: Implementieren eines Formulars, das eine Hintergrundoperation verwendet

Exemplarische Vorgehensweise: Ausführen eines Vorgangs im Hintergrund

Referenz

BackgroundWorker

Konzepte

Empfohlene Vorgehensweise für das verwaltete Threading

Weitere Ressourcen

Multithreading in Komponenten

Multithreading in Visual Basic

BackgroundWorker-Komponente