Queuing up an exit event.
Gavin Williams
761
Reputation points
In my app code I have:
if (args.VirtualKey == Windows.System.VirtualKey.Escape)
ExitApplication();
private void ExitApplication()
{
gfxTest.Stop();
}
The gfxTest class is running a thread:
public void Start()
{
CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
IAsyncAction mainLoopWorker;
WorkItemHandler workHandler = new WorkItemHandler((IAsyncAction action) =>
{
while (action.Status == AsyncStatus.Started && TaskState != TaskState.Exiting)
{
bool swapChainResized = CoreGraphics.SwapChain.UpdateSize();
if (CoreGraphics.SwapChain.Width == 0 || CoreGraphics.SwapChain.Height == 0)
continue;
CoreGraphics.SwapChain.ClearRTV(Color8bit.CornflowerBlue);
CoreGraphics.SwapChain.ClearDSV(0);
// Graphics test code here
CoreGraphics.Present();
}
// signal application quit or else ProcessUntilQuit will wait for windows close button press
Exit();
});
mainLoopWorker = ThreadPool.RunAsync(workHandler, WorkItemPriority.High, WorkItemOptions.TimeSliced);
// ProcessUntilQuit will block the UI thread and process events as they appear until the App terminates.
CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
}
My Exit function:
public void Exit()
{
CoreGraphics.Dispose();
Application.Current.Exit();
}
Application.Current.Exit will cause a catastrophic failure. So what I want is some way to queue up a normal application exit event for the event processor to catch.
Sign in to answer