Skip to content

Commit 93535b0

Browse files
Fix: Plausible Exception while closing an Application (#10631)
* Throw specific Win32Exception in PostMessage and move caller in try-catch * Pre-catch win32 error to avoid plausible thread issues * Update src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs Co-authored-by: h3xds1nz <[email protected]> --------- Co-authored-by: h3xds1nz <[email protected]>
1 parent 9c58920 commit 93535b0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/ManagedWndProcTracker.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
//#define LOGGING
@@ -120,7 +120,12 @@ private static void HookUpDefWindowProc(IntPtr hwnd)
120120
try
121121
{
122122
result = UnsafeNativeMethods.SetWindowLong(new HandleRef(null,hwnd), NativeMethods.GWL_WNDPROC, defWindowProc);
123-
}
123+
124+
if (result != IntPtr.Zero)
125+
{
126+
UnsafeNativeMethods.PostMessage(new HandleRef(null, hwnd), WindowMessage.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
127+
}
128+
}
124129
catch(System.ComponentModel.Win32Exception e)
125130
{
126131
// We failed to change the window proc. Now what?
@@ -133,10 +138,6 @@ private static void HookUpDefWindowProc(IntPtr hwnd)
133138
throw;
134139
}
135140
}
136-
if (result != IntPtr.Zero )
137-
{
138-
UnsafeNativeMethods.PostMessage(new HandleRef(null,hwnd), WindowMessage.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
139-
}
140141
}
141142
}
142143

0 commit comments

Comments
 (0)