Could someone explain me why this code is not working :
...
foreach (VisualChunk chunk in SortedChunks)
{
System.Action a = () => MyFunction_Threaded(chunk);
Console.Write("Synchronous : ");
a.Invoke();
System.Threading.Tasks.Task.Factory.StartNew(
a,
CancellationToken.None,
TaskCreationOptions.None,
TaskScheduler.Default)
}
...
private void MyFunction_Threaded(VisualChunk chunk)
{
Console.WriteLine(chunk.ChunkID);
}
It gives me the following output at console :
Synchronous : 0
Synchronous : 1
Synchronous : 2
Synchronous : 3
Synchronous : 4
Synchronous : 4294967291
Synchronous : 4294967292
Synchronous : 4294967293
Synchronous : 4294967294
Synchronous : 4294967295
Synchronous : 4294967296
Synchronous : 4294967297
4294967297
4294967297
4294967297
4294967297
4294967297
4294967297
4294967297
4294967297
4294967297
4294967297
4294967297
Synchronous : 4294967298
4294967298
In fact this code is working perfectly when .net framework 4.5 is installed (win 8 or VS2012). When only the 4.0 is installed, this problem is raising !