Skip to content

Commit

Permalink
Fix timer thread safety related crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 3, 2023
1 parent 39b55cc commit 0ff7fe0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/PixiEditor/Models/Controllers/MouseUpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ public MouseUpdateController(UIElement uiElement, MouseEventHandler onMouseMove)
element = uiElement;

_timer = new System.Timers.Timer(MouseUpdateIntervalMs);
_timer.AutoReset = true;
_timer.Elapsed += TimerOnElapsed;

element.MouseMove += OnMouseMove;
}

private void TimerOnElapsed(object sender, ElapsedEventArgs e)
{
_timer.Stop();
element.MouseMove += OnMouseMove;
Application.Current?.Dispatcher.Invoke(() =>
{
element.MouseMove += OnMouseMove;
});
}

private void OnMouseMove(object sender, MouseEventArgs e)
Expand Down

0 comments on commit 0ff7fe0

Please sign in to comment.