Home > front end >  WPF async in Current Dispatcher
WPF async in Current Dispatcher

Time:04-16

I'm updating my WPF app from .net 4.6 Framework to .net 6. For some reason I can't find the correct way to execute async code in the dispatcher.

private async Task HandleNotFromUI()
{
  await Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, HadleCommandArgsAsync);
}
private async Task SomeMethodAsync()
{
   someCode();
   await someAsyncCode();
   someMoreCode();
}

And it "looses" the thread on await someAsyncCode and does not hit someMoreCode. Similar code was working fine before updating to .net 6. Is it something about .net 6 or WPF in .net 6 or I'm making some mistake?

CodePudding user response:

Changed Dispatcher.CurrentDispatcher to App.Current.Dispatcher and it is working. I'm not sure why though.

  • Related