Improve WinUI 3 sample app (#295)
* Fix WinUI sample app crash when closing * Tweak WinUI 3 sample project files Also disables ReadyToRun for Debug builds
このコミットが含まれているのは:
1 親
76a83967dc
コミット
84b79f0f9b
6ファイル変更
+69
-27
検索条件に一致するファイルはありません
@@ -1,4 +1,6 @@
|
||||
using ComputeSharp.SwapChain.WinUI.Views;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using ComputeSharp.SwapChain.WinUI.Views;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI;
|
||||
@@ -6,12 +8,18 @@ namespace ComputeSharp.SwapChain.WinUI;
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
public sealed partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// The main application window
|
||||
/// </summary>
|
||||
private Window? mainWindow;
|
||||
private MainWindow? mainWindow;
|
||||
|
||||
/// <summary>
|
||||
/// A timer to force shutdown after a given amount of time.
|
||||
/// </summary>
|
||||
/// <remarks>This field is needed to keep the timer alive.</remarks>
|
||||
private Timer? shutdownTimer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
@@ -26,7 +34,18 @@ public partial class App : Application
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
mainWindow = new MainWindow();
|
||||
mainWindow.Closed += (_, _) => Exit();
|
||||
mainWindow.Closed += (_, _) =>
|
||||
{
|
||||
// Due to an issue (https://discord.com/channels/372137812037730304/663434534087426129/979543152853663744), the WinUI 3 app
|
||||
// will keep running after the window is closed if any render thread is still going. To work around this, each loaded shader
|
||||
// panel is tracked in a conditional weak table, and then when the window is closed they're all manually stopped by setting
|
||||
// their shader runners to null. After this, the app should just be able to close automatically when the panels are done.
|
||||
mainWindow.OnShutdown();
|
||||
|
||||
// For good measure, also start a timer of one second. If the app is still alive by then (ie. if the timer callback is
|
||||
// executed at all), then just force the whole process to terminate, and exit with the E_APPLICATION_EXITING error code.
|
||||
shutdownTimer = new Timer(_ => Environment.Exit(unchecked((int)(0x8000001A))), this, 1000, Timeout.Infinite);
|
||||
};
|
||||
mainWindow.Activate();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする