Apmācība
Modulis
Use Microsoft Dynamics 365 Customer Service queues to manage case workloads - Training
Learn about using Microsoft Dynamics 365 Customer Service queues to manage case workloads.
Šī pārlūkprogramma vairs netiek atbalstīta.
Jauniniet uz Microsoft Edge, lai izmantotu jaunāko līdzekļu, drošības atjauninājumu un tehniskā atbalsta sniegtās priekšrocības.
After a thread exits its event loop, it must shut down its DispatcherQueue. Doing so raises the ShutdownStarting and ShutdownCompleted events, and drains any final pending enqueued items before disabling further enqueuing.
When you call either DispatcherQueueController.ShutdownQueueAsync or DispatcherQueueController.ShutdownQueue, the order of events raised is the following:
The events are separated into application/framework categories so that orderly shutdown can be achieved. That is, by explicitly raising application shutdown ahead of framework shutdown events, there's no danger that a framework component will be in an unusable state as the application winds down.
namespace winrt
{
using namespace Microsoft::UI::Dispatching;
}
// App runs its own custom message loop.
void RunCustomMessageLoop()
{
// Create a DispatcherQueue.
auto dispatcherQueueController{winrt::DispatcherQueueController::CreateOnCurrentThread()};
// Run a custom message loop. Runs until the message loop owner decides to stop.
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!ContentPreTranslateMessage(&msg))
{
TranslateMesasge(&msg);
DispatchMessage(&msg);
}
}
// Run down the DispatcherQueue. This single call also runs down the system DispatcherQueue
// if one was created via EnsureSystemDispatcherQueue:
// 1. Raises DispatcherQueue.ShutdownStarting event.
// 2. Drains remaining items in the DispatcherQueue, waits for deferrals.
// 3. Raises DispatcherQueue.FrameworkShutdownStarting event.
// 4. Drains remaining items in the DispatcherQueue, waits for deferrals.
// 5. Disables further enqueuing.
// 6. Raises the DispatcherQueue.FrameworkShutdownCompleted event.
// 7. Raises the DispatcherQueue.ShutdownCompleted event.
dispatcherQueueController.ShutdownQueue();
}
DispatcherQueue supports custom message loops. However, for simple apps that don't need customization, we provide a default implementations. That removes a burden from developers, and helps ensure consistently correct behavior.
namespace winrt
{
using namespace Microsoft::UI::Dispatching;
}
// Simple app; doesn't need a custom message loop.
void RunMessageLoop()
{
// Create a DispatcherQueue.
auto dispatcherQueueController{winrt::DispatcherQueueController::CreateOnCurrentThread()};
// Runs a message loop until a call to DispatcherQueue.EnqueueEventLoopExit or PostQuitMessage.
dispatcherQueueController.DispatcherQueue().RunEventLoop();
// Run down the DispatcherQueue.
dispatcherQueueController.ShutdownQueue();
}
// May be called while receiving a message.
void RunNestedLoop(winrt::DispatcherQueue dispatcherQueue)
{
// Runs a message loop until a call to DispatcherQueue.EnqueueEventLoopExit or PostQuitMessage.
dispatcherQueue.RunEventLoop();
}
// Called to break out of the message loop, returning from the RunEventLoop call lower down the
// stack.
void EndMessageLoop(winrt::DispatcherQueue dispatcherQueue)
{
// Alternatively, calling Win32's PostQuitMessage has the same effect.
dispatcherQueue.EnqueueEventLoopExit();
}
Some Windows App SDK components (for example, MicaController) depend on system components that in turn require a system DispatcherQueue (Windows.System.DispatcherQueue) running on the thread.
In those cases, the component that has a system DispatcherQueue dependency calls the EnsureSystemDispatcherQueue method, freeing your app from managing a system DispatcherQueue.
With that method called, the Windows App SDK DispatcherQueue manages the lifetime of the system DispatcherQueue automatically, shutting down the system DispatcherQueue alongside the Windows App SDK DispatcherQueue. Components might rely on both Windows App SDK and system DispatcherQueue shutdown events in order to ensure that they do proper cleanup after the message loop exits.
namespace winrt
{
using namespace Microsoft::UI::Composition::SystemBackdrops;
using namespace Microsoft::UI::Dispatching;
}
// The Windows App SDK component calls this during its startup.
void MicaControllerInitialize(winrt::DispatcherQueue dispatcherQueue)
{
dispatcherQueue.EnsureSystemDispatcherQueue();
// If the component needs the system DispatcherQueue explicitly, it can now grab it off the thread.
winrt::Windows::System::DispatcherQueue systemDispatcherQueue =
winrt::Windows::System::DispatcherQueue::GetForCurrentThread();
}
void AppInitialize()
{
// App doesn't need to concern itself with the system DispatcherQueue dependency.
auto micaController = winrt::MicaController();
}
The AppWindow class has functionality that integrates it with the DispatcherQueue, so that AppWindow objects can automatically be destroyed when the DispatcherQueueController.ShutdownQueueAsync or DispatcherQueueController.ShutdownQueue method is called.
There's also a property of AppWindow that allows callers to retrieve the DispatcherQueue associated with the AppWindow; aligning it with other objects in the Composition and Input namespaces.
AppWindow needs your explicit opt-in in order to be aware of the DispatcherQueue.
namespace winrt
{
using namespace Microsoft::UI::Dispatching;
using namespace Microsoft::UI::Windowing;
}
void Main()
{
// Create a Windows App SDK DispatcherQueue.
auto dispatcherQueueController{winrt::DispatcherQueueController::CreateOnCurrentThread()};
var appWindow = AppWindow.Create(nullptr, 0, dispatcherQueueController.DispatcherQueue());
// Since we associated the DispatcherQueue above with the AppWindow, we're able to retreive it
// as a property. If we were to not associate a dispatcher, this property would be null.
ASSERT(appWindow.DispatcherQueue() == dispatcherQueueController.DispatcherQueue());
// Runs a message loop until a call to DispatcherQueue.EnqueueEventLoopExit or PostQuitMessage.
dispatcherQueueController.DispatcherQueue().RunEventLoop();
// Rundown the Windows App SDK DispatcherQueue. While this call is in progress, the AppWindow.Destoyed
// event will be raised since the AppWindow instance is associated with the DispatcherQueue.
dispatcherQueueController.ShutdownQueue();
}
Windows developer atsauksmes
Windows developer ir atklātā pirmkoda projekts. Atlasiet saiti, lai sniegtu atsauksmes:
Apmācība
Modulis
Use Microsoft Dynamics 365 Customer Service queues to manage case workloads - Training
Learn about using Microsoft Dynamics 365 Customer Service queues to manage case workloads.
Dokumentācija
Threading functionality migration - Windows apps
This topic describes how to migrate the threading code in a Universal Windows Platform (UWP) application to the Windows App SDK.
Display WinRT UI objects that depend on CoreWindow - Windows apps
You can use certain pickers, popups, dialogs, and other Windows Runtime (WinRT) objects in your desktop app by adding a little bit of interoperation code.
Windows App SDK namespaces - Windows App SDK
User interface migration (including WinUI 3) - Windows apps
This topic shows how to migrate your user interface (UI) code, including migrating to [WinUI 3](../../../winui/index.md).