Why does it block? I know a solution with Dispatcher.PushFrame() but still. Is it the issue of a classic "Don't Block on Async Code" type?
class Program
{
static void Main(string[] args)
{
Test().Wait();
}
static async Task Test()
{
var disp = Dispatcher.CurrentDispatcher;
var t = Task.Run(() =>
{
disp.Invoke(() =>
{
Console.WriteLine("works");
});
});
await t.ConfigureAwait(false);
}
}
UPD: Now it waits synchronously on the main thread, and uses threadpool dispatcher and still blocks.
static void Main(string[] args)
{
Task.Run(async() => await Test()).Wait();
}
static async Task Test()
{
var disp = Dispatcher.CurrentDispatcher;
var t = Task.Run(() =>
{
disp.Invoke(() =>
{
Console.WriteLine("works");
});
});
await t.ConfigureAwait(false);
}