My app hangs and doesn't respond after I put my machine to sleep and then wake it again.
Here's my repro code:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
App.Current.Suspending += OnSuspending;
App.Current.Resuming += OnResuming;
}
private void OnSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
var syncObject = new Object();
var dispatcher = this.Dispatcher;
lock(syncObject)
{
Task.Run(() =>
{
lock (syncObject)
{
dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() =>
{
new MessageDialog("Oh no! Deadlock during suspension!").ShowAsync();
}).AsTask().Wait();
deferral.Complete();
}
}).Wait();
}
}
private async void OnResuming(object sender, object e)
{
await new MessageDialog("Hello, I resumed").ShowAsync();
}
}
What's more - if I use VS's lifecycle events buttons to force suspend/resume - VS also hangs.