We are observing something strange, code like this:
var task = new Task(...); // run in the background, do something lengthy work
task.ContinueWith(..., TaskScheduler.FromCurrentSynchronizationContext());
task.Start();
The second task there calls an event, which in turn tries to update the GUI, and we get the dreaded cross-thread exception.
Checking Thread.CurrentThread.ManagedThreadId
from the method in the second task there indicates that it is in fact not running on the UI thread.
The code that spawned the tasks is running on the UI thread.
Is there any scenario where this will go wrong?
TaskScheduler.FromCurrentSynchronizationContext
returns in the debugger. What do you find when you do this? – Acidity