I am noticing a pattern like below in few of my classes.
How can I abstract that away? Any suggestions?
private void InitializeClass()
{
BackgroundWorker bgw1 = new BackgroundWorker();
bgw1.DoWork += (s,e) =>
{
// doing work
};
BackgroundWorker bgw2 = new BackgroundWorker();
bgw2.DoWork += (s,e) =>
{
// doing work
};
BackgroundWorker bgw3 = new BackgroundWorker();
bgw3.DoWork += (s,e) =>
{
// doing work
};
bgw1.RunWorkerAsync();
bgw2.RunWorkerAsync();
bgw3.RunWorkerAsync();
}
and then:
or if you wanted to schedule multiple events:
UPDATE:
Here’s an alternative which allows you to specify a completed handler:
and then: