I'm using PushFrame to ensure that my window finishes drawing before executing additional code. My application has some time sensitive functions that require the windows have been updated before I continues executing code.
So I'm using the sample from msdn: http://msdn.microsoft.com/en-us/library/vstudio/system.windows.threading.dispatcher.pushframe(v=vs.110).aspx
Which works great, except, if a user is dragging my window when this code executes the window hangs and you can only get it back with a ctrl-alt-del.
Any ideas?
The application seems freezed because mouse capture is not automatically released from the window resize or DragMove()
operation after the Dispatcher.PushFrame()
is called from the user code.
The workaround would be to manually release mouse capture from any window in the application that is capturing the mouse prior to calling Dispatcher.PushFrame()
:
...
if (priority < DispatcherPriority.Loaded)
{
IntPtr capturingHandle = GetCapture();
for (int i = 0; i < Application.Current.Windows.Count; i++)
{
if (new WindowInteropHelper(
Application.Current.Windows[i]
).Handle == capturingHandle)
{
Mouse.Capture(
Application.Current.Windows[i],
CaptureMode.Element
);
Application.Current.Windows[i].ReleaseMouseCapture();
break;
}
}
}
...
This workaround utilizes the GetCapture()
p/invoke declaration:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetCapture();
Unfortunately I do not have a solution for you but can only confirm we can reproduce this too in our application (and in a 50 line example program). Feel free to vote for this connect issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With