Per the instructions at https://stackoverflow.com/a/11378213/892770, I've registered a global hotkey for my WPF app like this:
this.helper = new WindowInteropHelper(this);
this.source = HwndSource.FromHwnd(this.helper.Handle);
this.source.AddHook(this.HwndHook);
I'd like to make async calls from the hotkey handler to allow me to avoid hanging the UI thread and update the window piecemeal, for example:
private async Task OnHotKeyPressed()
{
this.MyText = "Loading...";
this.MyText = await CallRestApi();
}
Unfortunately I can't figure out how to do this. The AddHook method doesn't have an overload for async methods, and if I wrap my handler in a .Result, or AsyncContext.Run(...) the UI doesn't get updated until the whole method's done. Any ideas? Thanks!