Closed adamplonka closed 1 year ago
Could the AppWindow instance be cached inside of WindowManager instead of calling this code every time? ... Try to run and restart the (Unpackaged) version of application several times...
I'm not quite following here. You can't cache it across restarts. It would be different each time.
No, not across restarts. Currently all calls to set MinWidth, MinHeight etc first get an instance of AppWindow but this instance is created every time using AppWindow.GetFromWindowId
. I found this to be an issue because calls to this method randomly throw an exception in unpackaged mode. Usually it's fine to call this method once but after couple of calls it starts failing.
Oh and about restarts - once you reach the state where this method fails, it keeps failing even after application restart. Looks like it leaves some garbage in the system, I haven't yet figured what's really happening and the exact steps to reproduce, I just know it happens repetitively after some time, might be connected to windows sleep/hibernation mode (last time it happened to me was right after waking it from sleep). Apllication runs fine when not using any calls to AppWindow.
I don't think this is a bug in WinUiEx or that this library can do anything about it, looks like the bug is on much lower level, maybe in WinRT. Anyway WinUiEx can temporarily mitigate the issue by limiting calls to AppWindow.GetFromWindowId
before it gets fixed.
This to me sounds more like a pretty serious issue the WinAppSDK needs to fix soon. Sure caching it could reduce the likelihood of this happening early on and buy you a little more time, but ultimately running a few WinAppSDK apps and you're in for a full windows restart. The linked issue above doesn't seem to convey the behavior you're describing. @rkarman is an upcoming fix for this coming? Sounds pretty serious.
Just letting know that this error stopped occurring after one of windows updates. I'm still a little concerned about backward compatibility but as I couldn't reproduce this bug for quite a long time, I'm closing this issue for now.
This is the same issue as in https://github.com/microsoft/microsoft-ui-xaml/issues/6353 This code:
works in the (unpackaged) application, but using
WindowEx
or any method fromWindowManager
crashes with exceptionIt looks like
AppWindow.GetFromWindowId(wndId)
has a limited number of usages. Putting the above code in a loop results in an exception within couple of iterations. Could theAppWindow
instance be cached inside of WindowManager instead of calling this code every time?Steps to reproduce: