Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit cb1727e

Browse files
committed
Fix minor issue with [Window].GetHandle(true)
1 parent 54025f5 commit cb1727e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Toastify/src/Helpers/Extensions.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,23 @@ public static IntPtr GetHandle(this Window window)
6868
public static IntPtr GetHandle(this Window window, bool ensureHandle)
6969
{
7070
var wndHelper = new WindowInteropHelper(window);
71-
return ensureHandle ? wndHelper.EnsureHandle() : wndHelper.Handle;
71+
if (ensureHandle)
72+
{
73+
try
74+
{
75+
return wndHelper.EnsureHandle();
76+
}
77+
catch (InvalidOperationException)
78+
{
79+
// ignore
80+
}
81+
catch (Exception e)
82+
{
83+
logger.Error($"Unhandled exception in {nameof(WindowInteropHelper.EnsureHandle)}", e);
84+
}
85+
}
86+
87+
return wndHelper.Handle;
7288
}
7389

7490
public static bool IsModifierKey(this Key key)

0 commit comments

Comments
 (0)