Skip to content

Commit 4836b04

Browse files
committed
Calc: Step 3: Start and shutdown a DispatcherQueue as the App starts and shuts down
1 parent 821075b commit 4836b04

File tree

1 file changed

+17
-0
lines changed
  • Samples/Islands/DrawingIsland/CalculatorDemo

1 file changed

+17
-0
lines changed

Samples/Islands/DrawingIsland/CalculatorDemo/App.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// // Copyright (c) Microsoft. All rights reserved.
22
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using Microsoft.UI.Dispatching;
45
using System.Windows;
56

67
namespace CalculatorDemo
@@ -10,5 +11,21 @@ namespace CalculatorDemo
1011
/// </summary>
1112
public partial class App : Application
1213
{
14+
// Many WinAppSDK APIs require a DispatcherQueue to be running on the thread. We'll start one when the app starts up
15+
// and shut it down when the app is finished.
16+
protected override void OnStartup(StartupEventArgs e)
17+
{
18+
_dispatcherQueueController = DispatcherQueueController.CreateOnCurrentThread();
19+
base.OnStartup(e);
20+
}
21+
22+
protected override void OnExit(ExitEventArgs e)
23+
{
24+
base.OnExit(e);
25+
_dispatcherQueueController?.ShutdownQueue();
26+
_dispatcherQueueController = null;
27+
}
28+
29+
DispatcherQueueController? _dispatcherQueueController;
1330
}
1431
}

0 commit comments

Comments
 (0)