I am tearing my hair off because of the following issue. I have this bit of code that loops through a list of objects and creates a processing task for each of them.
IList<TileInfo> tiles = tileSource.Schema.GetTilesInView(extent, level);
List<Task> renderingTasks = new List<Task>();
foreach (TileInfo info in tiles) {
renderingTasks.Add(Task.Factory.StartNew(new Action(delegate {
Console.WriteLine(Task.CurrentId +"Info object"+ info.GetHashCode());
}
})));
}
This code prints:
1Info object36963566
2Info object36963566
3Info object36963566
4Info object36963566
5Info object36963566
6Info object36963566
7Info object36963566
8Info object36963566
9Info object36963566
10Info object36963566
11Info object36963566
12Info object36963566
...
As you can see, the problem is that the tasks seem to all have a reference to one object!
Why are the tasks all using only one object from the list?
Thanks for you help