Skip to content

windowManager.destroy() takes several seconds to complete with Flutter 3.24.0 #478

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

Open
TomKrauss opened this issue Aug 9, 2024 · 11 comments

Comments

@TomKrauss
Copy link

We use windowManager.destroy() in our application to shut down. This worked smoothly in the past and now with the upgrade to Flutter 3.24.0 it takes several seconds to complete and to finally shutdown the application.

Tested on Windows.

@li9chuan
Copy link

li9chuan commented Aug 9, 2024

I've encountered the same issue. The windowManager.destroy() method is taking several seconds to complete the shutdown process after upgrading to Flutter 3.24.0 on Windows. Previously, it worked smoothly and completed much faster.

@azlekov
Copy link

azlekov commented Aug 14, 2024

Same issue!
Any workaround or how you approach this guys @TomKrauss, @li9chuan?

@TomKrauss
Copy link
Author

Unfortunately no.

@li9chuan
Copy link

The Flutter version has been rolled back to 3.22.3, and window_manager has also been downgraded to 0.3.9 because of issue 483.
@azlekov

@WinXaito
Copy link

Same issue! Any workaround or how you approach this guys @TomKrauss, @li9chuan?

@azlekov I encoutered the same problem. For the moment, I added exit(0); after calling await windowManager.destroy();

So, like that the function onWindowClose() is still called and completed, and with the exit(0);, the app is instantly closed after. Maybe not the best solution, but I didn't encoure any problem at this time.

@override
void onWindowClose() async {
  bool isPreventClose = await windowManager.isPreventClose();
  if (isPreventClose) {
    // ... disposing all my componenents, upgrade prefs, etc.

    // Close app
    await windowManager.destroy();
    exit(0);
  }
}

@AminBhst
Copy link

AminBhst commented Oct 18, 2024

Rolling back Flutter to 3.22.3 and window_manager to 0.3.9 fixes the issue on development runs but the issue still persists for release builds. I also added the exit(0); and it didn't work. Any ideas?

@WinXaito
Copy link

@AminBhst

Rolling back Flutter to 3.22.3 and window_manager to 0.3.9 fixes the issue on development runs but the issue still persists for release builds. I also added the exit(0); and it didn't work. Any ideas?

I had the same problem. The dll window_manager_plugin.dll is not correctly updated. So, you can remove the DLL (folder build\windows\x64\runner\Release or do a flutter clean and build your app again. This should work. (So you can use flutter 3.24 with window_manager 0.3.9 with the exit(0); and it should work fine.

@AminBhst
Copy link

@AminBhst

Rolling back Flutter to 3.22.3 and window_manager to 0.3.9 fixes the issue on development runs but the issue still persists for release builds. I also added the exit(0); and it didn't work. Any ideas?

I had the same problem. The dll window_manager_plugin.dll is not correctly updated. So, you can remove the DLL (folder build\windows\x64\runner\Release or do a flutter clean and build your app again. This should work. (So you can use flutter 3.24 with window_manager 0.3.9 with the exit(0); and it should work fine.

Thank you. I did try a flutter clean as well but to no avail. Starting to give up on this lol

@7Eltantawy
Copy link

#502 I have tried this and it works well for me.

  @override
  Future onWindowClose() async {
    final bool isPreventClose = await windowManager.isPreventClose();
    if (!isPreventClose) return;
    if (!mounted) return;

    final result = await showAskExitDialog(context);
    if (result == null || !result) return;

    await windowManager.setPreventClose(false);
    await windowManager.close();
  }

@tenglongwentian
Copy link

在组件system_tray菜单点击退出如下所示,可以避免卡顿
MenuItemLabel( label: '退出', onClicked: (menuItem) async => { await windowManager.setPreventClose(false), await windowManager.close(), }, ),

@cybrox
Copy link

cybrox commented May 5, 2025

I can reproduce this issue on Flutter 3.29.2 still.

Minimal example of a project that causes the issue: Gist File A
Minimal example of a project that does not cause the issue: Gist File B

The fix works by changing windowManager.destroy() to windowManager.setPreventClose(false); windowManager.close(); as suggested by @tenglongwentian. (Thanks!)

The reason for the several second delay is that the app actually crashes with the following exception:

Exception thrown at 0x00007FF83684D9D0 (flutter_windows.dll) in tester.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

Call stack:
 	flutter_windows.dll!00007ff83684d9d0()	Unknown
 	flutter_windows.dll!00007ff836845ce0()	Unknown
>	tester.exe!flutter::FlutterViewController::HandleTopLevelWindowProc(HWND__ * hwnd, unsigned int message, unsigned __int64 wparam, __int64 lparam) Line 48	C++
 	tester.exe!FlutterWindow::MessageHandler(HWND__ * hwnd, const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 59	C++
 	tester.exe!Win32Window::WndProc(HWND__ * const window, const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 170	C++
 	[External Code]	
 	tester.exe!flutter::FlutterViewController::~FlutterViewController() Line 30	C++
 	[External Code]	
 	tester.exe!FlutterWindow::~FlutterWindow() Line 10	C++
 	tester.exe!wWinMain(HINSTANCE__ * instance, HINSTANCE__ * prev, wchar_t * command_line, int show_command) Line 42	C++
 	[External Code]	

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants