Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Winforms Click event slower than the MouseClick event?

I'm adding buttons to form with loop and i noticed adding click event handlers slowing down application too much. Later i tried mouse click event instead click event and it is working instantly.

This screenshot showing my test result: alt text Source code: http://pastebin.com/qVewNm1u

Results for 1000 event handler:
Click: 2892ms MouseClick: 1ms

I can't figure out why Click event very slow.

Edit: If i change build platform target to x64 or Any CPU, results changing: Click: 5, MouseClick: 9 Look like x86 platform target causing this problem but still x64 results not good too compared to x86 MouseClick time (1ms).

Edit2: I changed screenshot now it will show better result.

Edit3: https://connect.microsoft.com/VisualStudio/feedback/details/597039/winforms-click-event-slower-than-the-mouseclick-event

like image 300
Jaex Avatar asked Sep 11 '10 02:09

Jaex


People also ask

What is the difference between click and MouseClick?

If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. However, the MouseClick event will not be raised if the click is caused by action other than that of the mouse, such as pressing the ENTER key.

What is click event C#?

The Click Event for C# Form ButtonsThe Message is displaying which object was the sender of the event, as well as displaying the Text property of the sender: the button with the Text "button1".


1 Answers

I repro, but it is specific to VS2010. There is no such behavior in VS2008, both execute in less than 1 tick. It also doesn't depend on the .NET version.

This looks like a defect in IntelliTrace, available in the Ultimate edition. Trying to dig deeper and turning unmanaged code debugging on removed the effect. Project + Properties, Debug tab, tick "Enable unmanaged code debugging". Also, running the program without the debugger (Ctrl+F5) removed the effect. The slam-dunk is Tools + Options, IntelliTrace, General, untick Enable to remove the effect.

I recommend you post your findings to connect.microsoft.com. You can reference this thread in your feedback report. Everything they need to know to diagnose the problem is available.

As noted, the workaround is to disable IntelliTrace. This is guaranteed to not be a problem on your customer's machine.

like image 128
Hans Passant Avatar answered Oct 01 '22 07:10

Hans Passant