Using Thread is pretty simple
Thread thread = new Thread(MethodWhichRequiresSTA); thread.SetApartmentState(ApartmentState.STA);
How to do the same using tasks in a WPF application? Here is the code:
Task.Factory.StartNew ( () => {return "some Text";} ) .ContinueWith(r => AddControlsToGrid(r.Result));
I get an InvalidOperationException with
The calling thread must be an STA because it requires many user interface components.
multithreading c # thread-safety wpf task-parallel-library
Michel Triana May 11 '11 at 23:24 2011-05-11 23:24
source share