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
.