window_manager icon indicating copy to clipboard operation
window_manager copied to clipboard

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

Open TomKrauss opened this issue 1 year ago • 11 comments

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.

TomKrauss avatar Aug 09 '24 05:08 TomKrauss

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.

li9chuan avatar Aug 09 '24 09:08 li9chuan

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

azlekov avatar Aug 14 '24 14:08 azlekov

Unfortunately no.

TomKrauss avatar Aug 14 '24 17:08 TomKrauss

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

li9chuan avatar Aug 16 '24 06:08 li9chuan

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);
  }
}

WinXaito avatar Aug 27 '24 14:08 WinXaito

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?

AminBhst avatar Oct 18 '24 13:10 AminBhst

@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.

WinXaito avatar Oct 18 '24 13:10 WinXaito

@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

AminBhst avatar Oct 18 '24 14:10 AminBhst

#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();
  }

7Eltantawy avatar Oct 19 '24 00:10 7Eltantawy

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

tenglongwentian avatar Mar 14 '25 08:03 tenglongwentian

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]	

cybrox avatar May 05 '25 11:05 cybrox