Search code examples
wpfasync-awaitwindows-10tabletmessagebox

MessageBox.Show causing blocking after close on Windows 10 tablet


We have a WPF app that also runs on a tablet. We are targeting Windows 10, .Net 4.6.2.

We have an async event handler that calls MessageBox.Show. The user clicks Yes and the app continues on doing some stuff.

When the app runs on tablet hardware, the app locks up for 10-20 seconds after the event completes. I cannot duplicate this from the desktop or in the simulator, only when it actually runs on the tablet.

I have isolated it to the MessageBox. When I take it out the app behaves normally. I feel like maybe it has something to do with threading.

Any ideas?


Solution

  • Based on @stuicidle's clue, I went down a better research path. Many people have tried to solve the async MessageBox problem.

    I ultimately got my solution from how can i use Messagebox.Show in async method on Windows Phone 8?

    My code looks like this:

    private async Task HandleEvent()
    {
        var message = $"Continue?";
        MessageBoxResult result = MessageBoxResult.None;
        var dg = new Action(() => result = MessageBox.Show(message, "Warning", MessageBoxButton.YesNo));
        await Dispatcher.BeginInvoke(dg);
    
        if (result == MessageBoxResult.Yes)
            await DoSomeStuff();
    }