When i ran this piece of code
private void button1_Click(object sender, EventArgs e)
{
Start(sender, e);
}
private void Start(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
System.Threading.Tasks.Task.Factory.StartNew(() => dosomething(i));
Debug.WriteLine("Called " + i);
}
Debug.WriteLine("Finished");
}
public void dosomething(int i)
{
Debug.WriteLine("Enters " + i);
lock (this)
{
Debug.WriteLine("Working " + i);
Thread.Sleep(100);
}
Debug.WriteLine("Done " + i);
}
output is different with .Net version 4.0 and 4.5. With 4.0 number 5 is repeated I can see the reason value of i is moved to 5 before some of the Tasks executed but same code with 4.5 shows different output.
(output ran with VS 2010 .Net 4.0)
Called 0
Called 1
Enters 1
Working 1
Called 2
Called 3
Called 4
Finished
Enters 0
Done 1
Enters 5
Working 0
Working 5
Done 0
**Enters 5
Working 5
Done 5
Enters 5
Done 5
Working 5
Done 5**
but when i ran with .Net 4.5 (VS 2011 beta) the result is,
(output ran with VS 2011 beta .Net 4.5)
Enters 0
Working 0
Called 0
Called 1
Enters 2
Called 2
Enters 2
Enters 3
Called 3
Called 4
Finished
Done 0
Working 2
Enters 5
Done 2
Working 3
Done 3
Working 5
Done 5
Working 2
Done 2
I couldn't see changes done with Task under CLR 4.5? Can anyone point me what are the changes with .Net 4.5 please.