Krypton-Suite-Legacy-Archive / Krypton-NET-5.470

A update to Component factory's krypton toolkit to support the .NET 4.7 framework.
BSD 3-Clause "New" or "Revised" License
78 stars 20 forks source link

Prevent crash when a form is disposed immediately during closing #217

Closed jpatte closed 5 years ago

jpatte commented 5 years ago

Hello,

When the DefaultCloseRequest property of the KryptonDockingManager is set to RemovePageAndDispose, closing a floating window crashes the application.

Steps to reproduce: in the "Navigator + FloatingWindows 2019" example (from Krypton Docking examples), set the DockingAllowClose flag of the new pages to allow the user to close them, set the DefaultCloseRequest property of the KryptonDockingManager to RemovePageAndDispose, then run the project and close a floating window.

The same issue can occur when a floating window is disposing immediately at closing, even if a different DefaultCloseRequest is used.

This issue is caused by the ShadowManager.FlashWindowExListener class which does not expect the window to be possibly disposed before the Closing event is fired. It tries to access the Handle property of the window to remove it from its internal list of forms, however that property cannot be accessed after the window has been disposed and that causes a crash.

The fix is to adapt its Closing event handler to use the window's handle directly (stored in a closure) rather than a reference to the window.