Take the 2-minute tour ×  Let's say I want to sent an int
parameter to a background worker, how can this be accomplished?
private void worker_DoWork(object sender, DoWorkEventArgs e) {
I know when this is worker.RunWorkerAsync();, I don't understand
how to define in worker_DoWork that it should take an int
parameter.  share|improve this question  6 Answers 6  up vote 78
down vote accepted  You start it like this:  int value = ...;
bgw1.RunWorkerAsync(value);  // argument: value,  the int will
be boxed  and then  private void worker_DoWork(object sender,
DoWorkEventArgs e)     int value = (int) e.Argument;   // the
'argument' parameter resurfaces here share|improve this answer
How can I do two arguments? –  sooprise Jan 26 '11 at 16:45 Or
do I send an object full of more than one argument? –  sooprise
Jan 26 '11 at 16:46 @soo: Use a helper class or a Tuple<A,B>
(C#4+) (Edit: Yes, use an object to pack it all in. See for
example DoWorkEventArgs self). –  Henk Holterman Jan 26 '11 at
16:47 Ok, thanks :) !! – 