Skip to content

Commit cfbb29d

Browse files
Add Hang Prevention guidance from Sébastien Lachance
https://www.dotnetapp.com/hang-on/
1 parent ee38f3a commit cfbb29d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Microsoft.Toolkit.Uwp.SampleApp/App.xaml.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Threading.Tasks;
67
using Microsoft.Toolkit.Uwp.Helpers;
78
using Microsoft.Toolkit.Uwp.SampleApp.Common;
89
using Microsoft.Toolkit.Uwp.SampleApp.SamplePages;
@@ -163,7 +164,7 @@ private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
163164
/// </summary>
164165
/// <param name="sender">The source of the suspend request.</param>
165166
/// <param name="e">Details about the suspend request.</param>
166-
private void OnSuspending(object sender, SuspendingEventArgs e)
167+
private async void OnSuspending(object sender, SuspendingEventArgs e)
167168
{
168169
var deferral = e.SuspendingOperation.GetDeferral();
169170

@@ -179,7 +180,18 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
179180
// ignore
180181
}
181182

182-
deferral.Complete();
183+
try
184+
{
185+
await Task.Delay(2000);
186+
}
187+
catch
188+
{
189+
// ignore
190+
}
191+
finally
192+
{
193+
deferral.Complete();
194+
}
183195
}
184196
}
185197
}

0 commit comments

Comments
 (0)