soapergem
soapergem

Reputation: 9979

Why are touch interactions slower than click events in WPF?

I have an extremely bizarre scenario happening in my WPF application (which is in production). I have a couple of <Button> elements on the screen, which have Click events bound to them in the XAML code-behind. The click handler for the button uses HttpClient to hit a REST endpoint (using await/async), and then update the screen with the data it receives.

This application is running on some cheap Dell tablets, so touch screen is the primary mode of interaction. However for testing purposes I've plugged in a mouse.

When I use the mouse to click the button, the application is highly performant; in other words, it's fast. The REST call completes within 100 to 200 ms.

When I tap on the screen to press the button, which -- believe me -- I have confirmed hits the exact same click handler and performs the exact same code path, it usually isn't performant. Suddenly the exact same REST call takes much longer. Sometimes it takes 2 seconds. Other times it takes 10 seconds. I have no explanation for why this difference is occurring.

When I debug this same application on my Surface Pro 3 (much better hardware than the Dell tablet), I cannot reproduce the problem. But if it was purely a hardware issue I would have to wonder why it can be performant in some cases (using the mouse) but not others (using the touch screen).

I have been struggling to come up with a MVCE because my the slimmed-down offshoots I've tried creating don't seem to have this problem, but I will continue to try and edit this post if I can come up with one.

In the meantime, I'm wondering if anyone else has encountered any similar problem with touch screens. The only theory I have is that something about the WPF touch handler fires things on separate threads or separate contexts or with separate priorities (something like that).

Upvotes: 0

Views: 1212

Answers (1)

soapergem
soapergem

Reputation: 9979

So today I finally figured it out. I had a global TouchDown event handler registered in my App.xaml.cs file, using this code:

EventManager.RegisterClassHandler(typeof(UIElement), UIElement.TouchDownEvent, new EventHandler<TouchEventArgs>(MyEventHandler));

When I comment that line out, everything is perfectly performant 100% of the time. I see that the problem is that it's registered on every UIElement, when really I just want it registered on Window. That seems to have fixed my problem.

Upvotes: 1

Related Questions