.NET Framework Class Library
Window.OnClosing Method
Raises the Closing event.
Assembly: PresentationFramework (in PresentationFramework.dll)
Syntax
Visual Basic
Protected Overridable Sub OnClosing ( _ e As CancelEventArgs _ )
C#
protected virtual void OnClosing( CancelEventArgs e )
Visual C++
protected: virtual void OnClosing( CancelEventArgs^ e )
F#
abstract OnClosing : e:CancelEventArgs -> unit override OnClosing : e:CancelEventArgs -> unit
Parameters
- e
- Type: System.ComponentModel.CancelEventArgs
A CancelEventArgs that contains the event data.
Remarks
OnClosing raises the Closing event.
A type that derives from Window may override OnClosing. The overridden method must call OnClosing on the base class if Closing needs to be raised.
Version Information
.NET Framework
Supported in: 4, 3.5, 3.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also
Reference
Community Content
Alexandru Ghita
Re: Serious Threadsafety Issues
>> It seems to be that this method is invoked with a lock held <<
I am looking at how a dialog is closed using the Reflector, and I don't see a lock in the code. How do you know this?
I am looking at how a dialog is closed using the Reflector, and I don't see a lock in the code. How do you know this?
Daniel Normal Johnson
Serious Threadsafety Issues
It seems to be that this method is invoked with a lock held; If you display a dialog box (say, asking if the user wants to save data), then other UI threads that have their own windows block and their UI freezes
The behavor seems identical to what you get with RegisterClassCommandBinding, which is very unfortunate.
You can overcome this problem by using Dispatcher.BeginInvoke to run your dialog box after OnClosing() returns, but that is quite awkward. You need to set e.Cancel = true before you return, and then later close the window if appropriate.
The behavor seems identical to what you get with RegisterClassCommandBinding, which is very unfortunate.
You can overcome this problem by using Dispatcher.BeginInvoke to run your dialog box after OnClosing() returns, but that is quite awkward. You need to set e.Cancel = true before you return, and then later close the window if appropriate.