Skip to content

Commit 4f94b75

Browse files
authored
Merge pull request #525 from tgadv/fix-issue-501
Catch and handle exceptions in dispatcher thread
2 parents de75a24 + c940bc5 commit 4f94b75

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/GongSolutions.WPF.DragDrop/DragDrop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ private static void DoDragSourceMove(object sender, Func<IInputElement, Point> g
652652
DragDropPreview?.Move(getPosition(DragDropPreview.PlacementTarget));
653653
}
654654

655-
MouseHelper.HookMouseMove(point =>
655+
MouseHelper.HookMouseMove(dragHandler, point =>
656656
{
657657
if (DragDropPreview?.PlacementTarget != null)
658658
{

src/GongSolutions.WPF.DragDrop/Utilities/MouseHelper.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@ internal static class MouseHelper
99
{
1010
private static System.Windows.Threading.DispatcherTimer _timer;
1111

12-
internal static void HookMouseMove(Action<System.Windows.Point> mouseMoveHandler)
12+
internal static void HookMouseMove(IDragSource dragHandler, Action<System.Windows.Point> mouseMoveHandler)
1313
{
1414
_timer = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Input);
1515
_timer.Tick += (_, _) =>
1616
{
17-
if (TryGetCursorPos(out var lpPoint))
17+
try
1818
{
19-
mouseMoveHandler?.Invoke(new System.Windows.Point(lpPoint.x, lpPoint.y));
19+
if (TryGetCursorPos(out var lpPoint))
20+
{
21+
mouseMoveHandler?.Invoke(new System.Windows.Point(lpPoint.x, lpPoint.y));
22+
}
23+
}
24+
catch (Exception ex)
25+
{
26+
if (!dragHandler.TryCatchOccurredException(ex))
27+
{
28+
throw;
29+
}
2030
}
2131
};
2232
_timer.Interval = new TimeSpan(1);

0 commit comments

Comments
 (0)