DoWorkEventArgs.Argument Property
.NET Framework 4
Gets a value that represents the argument of an asynchronous operation.
Assembly: System (in System.dll)
The following code example demonstrates how to use the DoWorkEventArgs class to handle the DoWork event. For a full code listing, see How to: Run an Operation in the Background.
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; } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
How the Argument property is set
The Argument property is set with the value that you passed in when calling the RunWorkerAsync method overload that takes an argument parameter.
- 1/26/2012
- Matt Thalman
How do we populate e.Argument when the DoWork event fires?
I have not seen an example anywhere that shows how I can control the contents of e.Argument. All I see is examples like this one where it is presumed that someone somewhere has populated it already.
- 11/28/2011
- David Ziffer