Alternative to BackgroundWorker that accepts more than one argument? Alternative to BackgroundWorker that accepts more than one argument? multithreading multithreading

Alternative to BackgroundWorker that accepts more than one argument?


You could use a closure (Lambda):

backgroundWorker.DoWork += (s, e) => MyWorkMethod(userName, targetNumber);

Or with delegate (anonymous method) syntax:

backgroundWorker.DoWork +=     delegate(object sender, DoWorkEventArgs e)    {        MyWorkMethod(userName, targetNumber);    };


What's wrong with using a typed object?

internal class UserArgs{    internal string UserName { get; set; }    internal string TargetNumber { get; set; }}var args = new UserArgs() {UserName="Me", TargetNumber="123" };startCallWorker.RunWorkerAsync(args);


instead of a typed object. C# 4.0 provides us with tuple. We could use a tuple to hold multiple args. Then there is no need to declare a new class.