BackgroundWorker.RunWorkerAsync 메서드

정의

백그라운드 작업의 실행을 시작합니다.Starts execution of a background operation.

오버로드

RunWorkerAsync()

백그라운드 작업의 실행을 시작합니다.Starts execution of a background operation.

RunWorkerAsync(Object)

백그라운드 작업의 실행을 시작합니다.Starts execution of a background operation.

RunWorkerAsync()

백그라운드 작업의 실행을 시작합니다.Starts execution of a background operation.

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

예외

IsBusy이(가) true인 경우IsBusy is true.

예제

다음 코드 예제에서는 메서드를 사용 하 여 RunWorkerAsync 비동기 작업을 시작 하는 방법을 보여 줍니다.The following code example demonstrates the use of the RunWorkerAsync method to start an asynchronous operation. 이는 방법: 백그라운드에서 파일 다운로드에 설명 된 더 큰 예제의 일부입니다.It is part of a larger example described in How to: Download a File in the Background.

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메서드는 비동기적으로 실행 되는 작업을 시작 하는 요청을 제출 합니다.The RunWorkerAsync method submits a request to start the operation running asynchronously. 요청이 처리 되 면 DoWork 이벤트가 발생 하 고,이 이벤트가 발생 하 여 백그라운드 작업의 실행이 시작 됩니다.When the request is serviced, the DoWork event is raised, which in turn starts execution of your background operation.

백그라운드 작업이 이미 실행 중인 경우를 다시 호출 하면이 RunWorkerAsync 발생 InvalidOperationException 합니다.If the background operation is already running, calling RunWorkerAsync again will raise an InvalidOperationException.

추가 정보

적용 대상

RunWorkerAsync(Object)

백그라운드 작업의 실행을 시작합니다.Starts execution of a background operation.

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

매개 변수

argument
Object

DoWork 이벤트 처리기에서 실행될 백그라운드 작업에서 사용하는 매개 변수입니다.A parameter for use by the background operation to be executed in the DoWork event handler.

예외

IsBusy이(가) true인 경우IsBusy is true.

예제

다음 코드 예제에서는 메서드를 사용 하 여 RunWorkerAsync 비동기 작업을 시작 하는 방법을 보여 줍니다.The following code example demonstrates the use of the RunWorkerAsync method to start an asynchronous operation. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 BackgroundWorker 클래스입니다.This code example is part of a larger example provided for the BackgroundWorker class.

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

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

설명

RunWorkerAsync메서드는 비동기적으로 실행 되는 작업을 시작 하는 요청을 제출 합니다.The RunWorkerAsync method submits a request to start the operation running asynchronously. 요청이 처리 되 면 DoWork 이벤트가 발생 하 고,이 이벤트가 발생 하 여 백그라운드 작업의 실행이 시작 됩니다.When the request is serviced, the DoWork event is raised, which in turn starts execution of your background operation.

작업에 매개 변수가 필요한 경우 매개 변수를에 매개 변수로 제공할 수 있습니다 argument RunWorkerAsync .If your operation requires a parameter, you can provide it as the argument parameter to RunWorkerAsync.

백그라운드 작업이 이미 실행 중인 경우를 다시 호출 하면이 RunWorkerAsync 발생 InvalidOperationException 합니다.If the background operation is already running, calling RunWorkerAsync again will raise an InvalidOperationException.

추가 정보

적용 대상