async Task Main() + GUI

I just noticed the very nice feature with async Task Main.
However, the following piece of code acts a little unexpected.
//[STAThread] async Task Main() { await Task.Delay(TimeSpan.FromSeconds(1));// .ConfigureAwait(true); new Button(){Content = "A"}.Dump(); }
I would expect it to return to the execution context of the ui thread.
In comparison, this works:
async Task Main() { var disp = Dispatcher.CurrentDispatcher; await Task.Delay(TimeSpan.FromSeconds(1));//.ConfigureAwait(true); disp.Invoke(() => { new Button() {Content = "A"}.Dump(); }); }
Also is there a way to get the ui dispatcher so that one could dispatch work to the ui thread of the query? I noticed it is possible to just get the current dispatcher at the top of the query but that feels a little bit off for larger queries.

Thanks in advance.


Sign In or Register to comment.