.NET Forum / Visual Studio.NET / IDE / May 2008
Hooking system mouse, make VS dubugging difficult
|
|
Thread rating:  |
eschneider - 06 May 2008 19:37 GMT I'm Hooking system mouse events in my application, and when debugging the mouse locks for several seconds or forever. Is there anyway to prevent this?
This is related to the thread in microsoft.public.dotnet.languages.vb : Hook system mouse down? (4/29/2008)
using this method to hook events inside of a user control: http://www.colinneller.com/blog/PermaLink,guid,2838f59a-f4af-4c95-a322-b9ee5918a 39c.aspx
Thanks,
Schneider
Jialiang Ge [MSFT] - 07 May 2008 08:50 GMT Hello Schneider,
I downloaded example project from the link and reproduce the debugger hanging issue when I set a breakpoint on its callback functions (e.g. globalHooks_MouseMove). It can also be reproduced when I add a Thread.Sleep(10000) in globalHooks_MouseMove and run the program (Ctrl+F5) without debugging. The reason for the two scenarios is similar: The event handling thread stops due to the breakpoint or the sleep behavior, but our mouse is still moving, so the program or debugger is struggling when the next mouse move message comes, and it hangs. That's why we do not recommend to put time-consuming code logics in hook callback handlers. If we have to do it, we can create a new thread in the callback, and do the code logic in it.
Regards, Jialiang Ge (jialge@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights. =================================================
eschneider - 07 May 2008 15:57 GMT I don't have any time consuming logic in there.
It seems to be a conflict. Also are you using a dual proc pc? I'm on a single proc pc. I could thread this out, do you still think that would help?
Keep in mind the app runs fine, just trying to improve debugging.
Thanks, Schneider
> Hello Schneider, > [quoted text clipped - 26 lines] > rights. > ================================================= Jialiang Ge [MSFT] - 08 May 2008 07:11 GMT Hello Schneider,
I tested it in both dual and single processor computers, and it hangs on both. Threading it out does not help in debugging. But it does help if we run the program directly (Ctrl + F5), especially when the code in the event handler takes a relatively long time to run. In debugging, because we've essentially blocked the code path for handling the mouse move events with a breakpoint, so the mouse isn't going to move and hangs. I am sorry for this bad debugging experience, but honestly, this is really hard for a debugger. To overcome this, one workaround is to remote debugging from another machine, or run the target in a VM and remote debug that. Below I link to some VS remote debugging articles for your reference. I am asking the VS team for more suggestions and will get back to you as soon as possible. Thank you for your understanding.
How to implement remote debugging in Visual Studio 2005 http://support.microsoft.com/kb/910448
MSDN: Remote Debugging Setup: http://msdn.microsoft.com/en-us/library/y7f5zaaa(VS.71).aspx
Regards, Jialiang Ge (jialge@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights. =================================================
eschneider - 12 May 2008 16:23 GMT Thanks,
but remote debugging is not acceptable. Other .NET Framework items hook the mouse why don't they have this problem? I don't have any problems at run time.
Thanks, Schneider
> Hello Schneider, > [quoted text clipped - 35 lines] > rights. > ================================================= Jialiang Ge [MSFT] - 14 May 2008 05:29 GMT Hello Schneider,
This a note to let you know that I am still performing research on this issue and will get back to you as soon as possible. Yesterday, I find the hanging problem of Visual Studio debugger does not appear in Windows Vista with the same test steps. Based on my tests, it hangs in Windows 2003 and XP. I am working with the Visual Studio team to look into the reason. Thank you for your patience.
By the way, what did you mean by "Other .NET Framework items hook the mouse"? Would you please give me an example that does not have the hanging problem? I believe such an example will be very helpful to our researches. I appreciate your efforts.
Thanks Jialiang Ge (jialge@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights. =================================================
eschneider - 14 May 2008 15:29 GMT Hello, Jialiang
I'm using XP 64 to be specific. I would think the System.Windows.Forms.Form or System.Windows.Forms.Control hooks the system messages.
> Hello Schneider, > [quoted text clipped - 25 lines] > rights. > ================================================= Jialiang Ge [MSFT] - 16 May 2008 08:39 GMT Hello Schneider,
System.Windows.Forms.Form or System.Windows.Forms.Control does not hook system messages. They simply receive messages when other send/post to them. An example of local system hook is: http://support.microsoft.com/kb/319524, from which you will find it works differently from winform message loop.
Regarding the debugger hanging issue in Windows XP/2003, I find two alternatives these days:
1. LowLevelHooksTimeout Value
According to MSDN article: http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx The hook procedure should process a message in less time than the data entry specified in the LowLevelHooksTimeout value in the following registry key: HKEY_CURRENT_USER\Control Panel\Desktop The value is in milliseconds. If the hook procedure does not return during this interval, the system will pass the message to the next hook.
This timeout value explains why the mouse hangs for a few seconds when debugging. So a possible workaround is to set that key value something really small and see if that lets you get control of the mouse back and still debug your hook proc. Also be aware to log off and on to pick up the change, since user32.dll reads it only once during session startup.
2. Visual Studio can debug cross session and since debugger and debuggee will run on different desktops it is likely that they won't deadlock anymore. Therefore, in Windows XP, we can enable "Fast User Switching", and start the process in one session and attach our debugger to it from another user session.
Please let me know whether these suggestions help or not.
Regards, Jialiang Ge (jialge@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights. =================================================
eschneider - 16 May 2008 18:30 GMT Thanks, I will let you know if the time-out helps/works...
> Hello Schneider, > [quoted text clipped - 50 lines] > rights. > ================================================= eschneider - 19 May 2008 15:41 GMT I tried reducing by half to 2500, then rebooted, It did not seem to make a difference.
Think I need to go lower?
Schneider
> Hello Schneider, > [quoted text clipped - 50 lines] > rights. > ================================================= Jialiang Ge [MSFT] - 20 May 2008 10:23 GMT Hello Schneider,
Yes. I set it to be 50 or 100, logged off&on, then the hanging problem in debugger disappeared on my Windows 2003 machine. Please also note that the value LowLevelHooksTimeout, by default, does not exist in the HKEY_CURRENT_USER\Control Panel\Desktop key. We need to manually add a new REG_DWORD value if you don't see it. Please try it again and let me know how it works on your side.
Regards, Jialiang Ge (jialge@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights. =================================================
eschneider - 20 May 2008 14:58 GMT Ok, will try again later. Also the key was on my XP64 machine.
> Hello Schneider, > [quoted text clipped - 19 lines] > rights. > ================================================= schneider - 26 May 2008 18:05 GMT Ok, the value of 100 seems to be working.
Thanks, Schneider
> Hello Schneider, > [quoted text clipped - 19 lines] > rights. > ================================================= Jialiang Ge [MSFT] - 27 May 2008 03:32 GMT Thank you, Schneider, for the confirmation. It's a kind reminder that we'd better set the value back after the debugging.
Regards, Jialiang Ge (jialge@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights. =================================================
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|