Internal mouse handling in WPF app

Gabor Fazekas 1 Reputation point
2020-04-24T16:39:44.287+00:00

Hello,

I am building a game in wpf for a school project and I have noticed that the UI thread clogs up when I move the mouse over any window within the application (DispatcherTimer ticks are less frequent, which casues my game to lag and tear).

Is there a way to disable internal mouse handling, so I can have my own? Cursor is hidden by default so I do not really understand what is handled related to mouse movement in the background which could have such significant effect. Can you also shed some light on that as well. Thank you in advance!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,783 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Alex Li-MSFT 1,096 Reputation points
    2020-04-27T01:47:19.14+00:00

    Welcome to our Microsoft Q&A platform!

    I think you can use System.Windows.Threading.Timer to handle your tick.

    see the following link:

    why-does-the-dispatcher-timer-in-wpf-lag-when-i-hover-over-my-application-window

    Thanks.

    1 person found this answer helpful.
    0 comments No comments

  2. Mouad Cherkaoui 6 Reputation points
    2020-08-03T08:40:35.16+00:00

    Hi,
    you can try mouse handling with win32 apis, take a look to this document https://www.pinvoke.net/default.aspx/user32.mouse_event

    Best regards,
    Mouad.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.