I know that forms should be made on an STA thread because of the way forms work. But I assumed I can make a form object in any thread as long as I actually 'run' it in an STA thread, like with form.Show()
, form.ShowDialog()
or Application.Run(form)
, so its message loop is running on an STA thread.
If I run this code:
public async Task Test1() {
Console.WriteLine($"Threadpool: {Thread.CurrentThread.IsThreadPoolThread}");
Console.WriteLine("Start");
var form = new TextForm(); // Some basic form
Console.WriteLine("Middle");
await Task.Yield(); // This await never continues if run on threadpool
Console.WriteLine("End");
}
...then on an STA thread the code will reach 'End' immediately, but if run on a threadpool thread the code never reaches 'End'.