Reputation: 73
I have two methods below. Can you please tell me what each method do in brief and how does the two methods differ from each other ?
public void Method1()
{
foreach (string symbol in arrList)
{
Task.Factory.StartNew(() => DoWork(symbol));
}
}
public void Method2()
{
Task.Factory.StartNew(() =>
{
foreach (string symbol in arrList)
{
DoWork(symbol);
}
});
}
Upvotes: 0
Views: 132
Reputation: 332
The first will create many asynchronous Tasks that each call DoWork with the given symbol. The second will create one asynchronous Task that will do the entire loop before exiting.
Upvotes: 3