Async/await, ThreadPool and SetApartmentState Async/await, ThreadPool and SetApartmentState multithreading multithreading

Async/await, ThreadPool and SetApartmentState


Stephen Toub has already written an StaTaskScheduler (archive); I recommend you use that.

You can then construct a TaskFactory using that TaskScheduler. There is no equivalent to Task.Run on the TaskFactory type but you can easily create one using StartNew and Unwrap.