BackgroundWorker.RunWorkerAsync 메서드

정의

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

오버로드

Name Description
RunWorkerAsync()

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

RunWorkerAsync(Object)

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

RunWorkerAsync()

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

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

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

예외

IsBusytrue입니다.

예제

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

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

    // Disable the button for the duration of the download.
    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 (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
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 사용할 매개 변수입니다.

예외

IsBusytrue입니다.

예제

다음 코드 예제에서는 메서드를 사용하여 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

추가 정보

적용 대상