■ DispatcherQueueExtensions 클래스의 EnqueueAsync 확장 메소드를 사용해 DispatcherQueue 객체에서 특정 UI 스레드를 실행하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using System.Threading.Tasks; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml.Controls; using CommunityToolkit.WinUI; DispatcherQueue dispatcherQueue = DispatcherQueue.GetForCurrentThread(); await dispatcherQueue.EnqueueAsync ( () => { } ); int value1 = await dispatcherQueue.EnqueueAsync ( () => { return 42; } ); await dispatcherQueue.EnqueueAsync ( async () => { await Task.Delay(100); } ); int someOtherValue = await dispatcherQueue.EnqueueAsync ( async () => { await Task.Delay(100); return 42; } ); |