BackgroundWorker.RunWorkerAsync 메서드

정의

백그라운드 작업의 실행을 시작합니다.

오버로드

RunWorkerAsync()

백그라운드 작업의 실행을 시작합니다.

RunWorkerAsync(Object)

백그라운드 작업의 실행을 시작합니다.

RunWorkerAsync()

Source:
BackgroundWorker.cs
Source:
BackgroundWorker.cs
Source:
BackgroundWorker.cs

백그라운드 작업의 실행을 시작합니다.

public:
 void RunWorkerAsync();
public void RunWorkerAsync ();
member this.RunWorkerAsync : unit -> unit
Public Sub RunWorkerAsync ()

예외

IsBusy이(가) true인 경우

예제

다음 코드 예제에서는 메서드를 사용하여 RunWorkerAsync 비동기 작업을 시작하는 방법을 보여 줍니다. 방법 : 백그라운드에서 파일 다운로드에 설명된 더 큰 예제의 일부입니다.

private void downloadButton_Click(object sender, EventArgs e)
{
    // Start the download operation in the background.
    this.backgroundWorker1.RunWorkerAsync();

    // Disable the button for the duration of the download.
    this.downloadButton.Enabled = false;

    // Once you have started the background thread you 
    // can exit the handler and the application will 
    // wait until the RunWorkerCompleted event is raised.

    // Or if you want to do something else in the main thread,
    // such as update a progress bar, you can do so in a loop 
    // while checking IsBusy to see if the background task is
    // still running.

    while (this.backgroundWorker1.IsBusy)
    {
        progressBar1.Increment(1);
        // Keep UI messages moving, so the form remains 
        // responsive during the asynchronous operation.
        Application.DoEvents();
    }
}
Private Sub downloadButton_Click( _
    ByVal sender As Object, _
    ByVal e As EventArgs) _
    Handles downloadButton.Click

    ' Start the download operation in the background.
    Me.backgroundWorker1.RunWorkerAsync()

    ' Disable the button for the duration of the download.
    Me.downloadButton.Enabled = False

    ' Once you have started the background thread you 
    ' can exit the handler and the application will 
    ' wait until the RunWorkerCompleted event is raised.

    ' If you want to do something else in the main thread,
    ' such as update a progress bar, you can do so in a loop 
    ' while checking IsBusy to see if the background task is
    ' still running.
    While Me.backgroundWorker1.IsBusy
        progressBar1.Increment(1)
        ' Keep UI messages moving, so the form remains 
        ' responsive during the asynchronous operation.
        Application.DoEvents()
    End While
End Sub

설명

메서드는 RunWorkerAsync 비동기적으로 실행되는 작업을 시작하기 위한 요청을 제출합니다. 요청이 서비스 DoWork 되면 이벤트가 발생하며, 이 이벤트는 백그라운드 작업의 실행을 시작합니다.

백그라운드 작업이 이미 실행 중인 경우 를 다시 호출 RunWorkerAsync 하면 가 발생합니다 InvalidOperationException.

추가 정보

적용 대상

RunWorkerAsync(Object)

Source:
BackgroundWorker.cs
Source:
BackgroundWorker.cs
Source:
BackgroundWorker.cs

백그라운드 작업의 실행을 시작합니다.

public:
 void RunWorkerAsync(System::Object ^ argument);
public void RunWorkerAsync (object argument);
public void RunWorkerAsync (object? argument);
member this.RunWorkerAsync : obj -> unit
Public Sub RunWorkerAsync (argument As Object)

매개 변수

argument
Object

DoWork 이벤트 처리기에서 실행될 백그라운드 작업에서 사용하는 매개 변수입니다.

예외

IsBusy이(가) true인 경우

예제

다음 코드 예제에서는 메서드를 사용하여 RunWorkerAsync 비동기 작업을 시작하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 BackgroundWorker 클래스입니다.

// Start the asynchronous operation.
backgroundWorker1->RunWorkerAsync( numberToCompute );
// Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync(numberToCompute);

' Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync(numberToCompute)

설명

메서드는 RunWorkerAsync 비동기적으로 실행되는 작업을 시작하기 위한 요청을 제출합니다. 요청이 서비스 DoWork 되면 이벤트가 발생하며, 이 이벤트는 백그라운드 작업의 실행을 시작합니다.

작업에 매개 변수가 필요한 경우 에 매개 변수RunWorkerAsyncargument 제공할 수 있습니다.

백그라운드 작업이 이미 실행 중인 경우 를 다시 호출 RunWorkerAsync 하면 가 발생합니다 InvalidOperationException.

추가 정보

적용 대상