Mouse hook performace / separate thread
-
You chose the hard way for me :) ok, at least I'll exactly know what I'm doing. So I guess calling WaitMessage after creating that hook should help to create message quee on my thread?
zilo
Zilo(svk) wrote:
So I guess calling WaitMessage after creating that hook should help to create message quee on my thread?
<sarcasm> Yes, and then all the mouse move messages from the UI created in that thread will go into the queue. </sarcasm>
Zilo(svk) wrote:
ok, at least I'll exactly know what I'm doing.
Sure, if you say so. :rolleyes:
led mike
-
Zilo(svk) wrote:
So I guess calling WaitMessage after creating that hook should help to create message quee on my thread?
<sarcasm> Yes, and then all the mouse move messages from the UI created in that thread will go into the queue. </sarcasm>
Zilo(svk) wrote:
ok, at least I'll exactly know what I'm doing.
Sure, if you say so. :rolleyes:
led mike
-
Zilo(svk) wrote:
is it possible?
It's not possible the way you are thinking about it. What you can do is develop a solution by receiving the messages from the queue in the main thread and using your own implementation of inter-thread communications (there are many ways to do that like this one[^]) to pass the information on to the worker thread. Of course if you also require passing information back to the main thread ( like to display something in the UI ) you have to account for that as well.
led mike
-
Zilo(svk) wrote:
is it possible?
It's not possible the way you are thinking about it. What you can do is develop a solution by receiving the messages from the queue in the main thread and using your own implementation of inter-thread communications (there are many ways to do that like this one[^]) to pass the information on to the worker thread. Of course if you also require passing information back to the main thread ( like to display something in the UI ) you have to account for that as well.
led mike
I thought I can make it work running completely on separate thread. Otherwise it's not going to help me with performance. I have no heavy proccesses contected to that hook event, just simple things and still it doesn't perform well. But I have strong feeling that my performace lost is connected to mouse tracking over NC area, as I have implemented custom border painting which involves a lot of unmanaged API calls. I'll try to figure that out. anyway thanx for help. I didn't think that you will provide me with a straightforward answer like this one :)
zilo
-
I thought I can make it work running completely on separate thread. Otherwise it's not going to help me with performance. I have no heavy proccesses contected to that hook event, just simple things and still it doesn't perform well. But I have strong feeling that my performace lost is connected to mouse tracking over NC area, as I have implemented custom border painting which involves a lot of unmanaged API calls. I'll try to figure that out. anyway thanx for help. I didn't think that you will provide me with a straightforward answer like this one :)
zilo
-
Zilo(svk) wrote:
I didn't think that you will provide me with a straightforward answer
I can't possibly do that since I have no idea what actual problem you are trying to solve. You only posted what you think the problem is.
led mike
You already did by saying it's not possible. It's not really possible to post here all the code that it's used for the non-client painting, because it's quite a lot. However I can figure this out easily by removing that functionality to see if what happens.
zilo
-
You already did by saying it's not possible. It's not really possible to post here all the code that it's used for the non-client painting, because it's quite a lot. However I can figure this out easily by removing that functionality to see if what happens.
zilo
-
To my big surprise, removing that custom painting and sizing code didn't help at all. Do you have any idea how could I make it run smoother? Just the simple act of creating that mouse hook causes the whole UI to run not optimally...
zilo
Zilo(svk) wrote:
Just the simple act of creating that mouse hook causes the whole UI to run not optimally...
Sure there is no reason to hook mouse messages for the UI thread you are already running in yes? Are you creating a System Wide Hook? That would be even more expensive.
Zilo(svk) wrote:
non-client painting
You really need to specify your functional requirements if you want to receive any help on this problem.
led mike
-
Zilo(svk) wrote:
Just the simple act of creating that mouse hook causes the whole UI to run not optimally...
Sure there is no reason to hook mouse messages for the UI thread you are already running in yes? Are you creating a System Wide Hook? That would be even more expensive.
Zilo(svk) wrote:
non-client painting
You really need to specify your functional requirements if you want to receive any help on this problem.
led mike
Yes I'm making system wide hook. Let me explain why I'm hooking mouse events. I want to be able to use context help system. That means, by holding a specified key (CTRL for example) and left-clicking on a control, help file rather than control OnClick event will be raised. So I need to hook keyboard for my special key (that is running w/o problems) and mouse hook to catch any lef mouse click on my application form surface (any control), run the help file (.chm scrolled down to that control found by key-name). Rather than overriding OnClick in any possible control that I will ever use, I decided that the mouse hook is easier way how to accomplish this. dont worry about the NC painting anymore...
zilo
-
Yes I'm making system wide hook. Let me explain why I'm hooking mouse events. I want to be able to use context help system. That means, by holding a specified key (CTRL for example) and left-clicking on a control, help file rather than control OnClick event will be raised. So I need to hook keyboard for my special key (that is running w/o problems) and mouse hook to catch any lef mouse click on my application form surface (any control), run the help file (.chm scrolled down to that control found by key-name). Rather than overriding OnClick in any possible control that I will ever use, I decided that the mouse hook is easier way how to accomplish this. dont worry about the NC painting anymore...
zilo
And one more question. When I want hook only events regarding my Application Domain, I need to call SetWindowsHookEx with my AppDomain.GetCurrentThreadId() which is unmanaged thread id. Now this method is deprecated and msdn states that I should use ManagetThreadId instead. But this id is not working of course. How can I avoid AppDomain.GetCurrentThreadId() and still create the hook locally (which signifficantly improves the performance)?
zilo