1

バックグラウンドワーカーが完了したら、もう一度実行したいです。

backgroundWorker1.do作業してからbackgroundworkerを完了してからbackgroundworker1.doを実行してください...実行方法..多くのbackgroundworkerを何度も実行する必要があることに注意してください....ありがとうございます

4

3 に答える 3

1

イベントハンドラーRunWorkerAsync()に呼び出しを追加できますRunWorkerCompleted

    bw.RunWorkerCompleted += bw_RunWorkerCompleted;

    void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        ((BackgroundWorker)sender).RunWorkerAsync();
    }
于 2012-08-28T12:45:13.603 に答える
0

おそらく、同じプロパティで新しい Backgroundworker を作成するか、終了時に backgroundworker1.doWork() を呼び出すだけです。

于 2012-08-28T12:43:47.490 に答える
0

.NET 4.0 または .NET 4.5 を使用している場合は、BackgroundWorker の代わりにTasksを使用できます。

// Here your long running operation
private int LongRunningOperation()
{
   Thread.Sleep(1000);
   return 42;
}

// This operation will be called for processing tasks results
private void ProcessTaskResults(Task t)
{
   // We'll call this method in UI thread, so Invoke/BeginInvoke
   // is not required
   this.textBox.Text = t.Result;

}

// Starting long running operation
private void StartAsyncOperation()
{
   // Starting long running operation using Task.Factory
   // instead of background worker.
   var task = Task.Factory.StartNew(LongRunningOperation);   

   // Subscribing to tasks continuation that calls
   // when our long running operation finished
   task.ContinueWith(t =>
   {
      ProcessTaskResults(t);
      StartOperation();
   // Marking to execute this continuation in the UI thread!
   }, TaskScheduler.FromSynchronizationContext);
}

// somewhere inside you form's code, like btn_Click:
StartAsyncOperation();

タスクベースの非同期は、長時間実行される操作を処理する場合に適した方法です。

于 2012-08-28T13:12:35.777 に答える