-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispose() is not invoked when the application is closed #149
Comments
@davicbaba We've not been successful with this. Dispose() is called when you navigate or refresh a page, so we know that much works. We were not "gracefully" shutting down the WebView2 control and assumed that was the culprit. We implemented a graceful shutdown and ensured that the graceful shutdown is called, but Dispose() is still not being called. We found this and other issues claiming that Dispose() may not be called on certain browsers when the browser is closed or a tab is closed. There is no discussion I can find about the WebView2 control in particular. I honestly can't think of what else Blazor might be looking for from the browser control, other than a clean shutdown. FYI, the C++ code for the clean shutdown is void Photino::CloseWebView()
{
if (_webviewController != nullptr)
{
_webviewController->Close();
_webviewController = nullptr;
}
if (_webviewWindow != nullptr)
{
_webviewWindow->Stop();
_webviewWindow = nullptr;
}
if (_webviewEnvironment != nullptr)
{
_webviewEnvironment = nullptr;
}
} |
@MikeYeager I attempted a workaround to navigate to an intermediate page (e.g., Below is the relevant snippet from my private static NavigationManager _navigationManager;
[STAThread]
static void Main(string[] args)
{
var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args);
appBuilder.Services.AddLogging();
// Register root component
appBuilder.RootComponents.Add<App>("app");
var app = appBuilder.Build();
_navigationManager = app.Services.GetRequiredService<NavigationManager>();
// Customize window and register window closing handler
app.MainWindow
.SetIconFile("favicon.ico")
.SetTitle("Photino Hello World")
.RegisterWindowClosingHandler((_, _) =>
{
_navigationManager.NavigateTo("/closing"); //Navigate to closing page to force dispose
return false;
});
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
{
app.MainWindow.ShowMessage("Fatal exception", error.ExceptionObject.ToString());
};
app.Run();
} However, when executing navigation in the closing handler, I receive the following exception:
This suggests that, at the time of window closure, the Blazor navigation infrastructure is no longer in a valid state to perform navigation. Is there any existing option or a potential addition to Photino that would allow navigation to another page (or a similar action) during the closing process? This would force the current page to complete its lifecycle and invoke Dispose(), ensuring that resources are properly released and event subscriptions are canceled |
I have encountered an issue where the Dispose() method of components is never called when the application is closed directly.
Steps to reproduce:
Expected behavior:
The Dispose() method should be invoked when the application is closed.
Actual behavior:
The Dispose() method is not executed, preventing the ability to release resources, unsubscribe from events, and perform other necessary cleanup operations.
Additional resources:
The following image shows how the Dispose() method is not invoked in the mentioned project.
The text was updated successfully, but these errors were encountered: