DoWorkEventArgs.Argument 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得值,表示非同步作業的引數。
public:
property System::Object ^ Argument { System::Object ^ get(); };
public object Argument { get; }
public object? Argument { get; }
member this.Argument : obj
Public ReadOnly Property Argument As Object
屬性值
Object,表示非同步作業的引數。
範例
下列程式代碼範例示範如何使用 DoWorkEventArgs 類別來處理 DoWork 事件。 如需完整的程式代碼清單,請參閱 如何:在背景中執行作業。
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
// Do not access the form's BackgroundWorker reference directly.
// Instead, use the reference provided by the sender parameter.
BackgroundWorker bw = sender as BackgroundWorker;
// Extract the argument.
int arg = (int)e.Argument;
// Start the time-consuming operation.
e.Result = TimeConsumingOperation(bw, arg);
// If the operation was canceled by the user,
// set the DoWorkEventArgs.Cancel property to true.
if (bw.CancellationPending)
{
e.Cancel = true;
}
}
Private Sub backgroundWorker1_DoWork( _
sender As Object, e As DoWorkEventArgs) _
Handles backgroundWorker1.DoWork
' Do not access the form's BackgroundWorker reference directly.
' Instead, use the reference provided by the sender parameter.
Dim bw As BackgroundWorker = CType( sender, BackgroundWorker )
' Extract the argument.
Dim arg As Integer = Fix(e.Argument)
' Start the time-consuming operation.
e.Result = TimeConsumingOperation(bw, arg)
' If the operation was canceled by the user,
' set the DoWorkEventArgs.Cancel property to true.
If bw.CancellationPending Then
e.Cancel = True
End If
End Sub