|
|
|
start date: Wed, 22 Aug 2007 11:17:00 +0200,
posted on: microsoft.public.dotnet.general
back
| Thread Index |
|
1
Peter Larsen [] am
|
|
2
(Walter Wang [MSFT])
|
|
3
Peter Larsen [] am
|
|
4
Marc Gravell
|
|
5
Peter Larsen [] am
|
|
6
Marc Gravell
|
ManualResetEvent / WaitOne
Hi,
I have a problem using a ManuelResetEvent in the GUI thread while receiving
events from the Shell (new folders, rename etc).
This is what i do:
Receiving an event from the Shell.
Running some code - setting ManauelResetEvent.Reset().
The code continue - and somewhere else i test the handle
"ManuelResetEvent.WaitOne(100, true)" - still in the GUI thread.
While waiting (in WaitOne), the application receive yet another event from
the Shell - also in the main thread.
How is it possible to receive the second event while blocking the GUI thread
??
Thank you in advance
BR
Peter
Date:Wed, 22 Aug 2007 11:17:00 +0200
Author:
|
RE: ManualResetEvent / WaitOne
Hi Peter,
Sorry for delayed reply.
Could you please tell me more about your scenario? Are you watching for
file system changes? Preferrably a simple but complete and reproducible
project will be great for quick troubleshooting. Thanks.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Thu, 23 Aug 2007 06:15:55 GMT
Author:
|
Re: ManualResetEvent / WaitOne
Hi Walter,
I will try to create a small demo project within a few days !!
/Peter
Date:Thu, 23 Aug 2007 14:35:43 +0200
Author:
|
Re: ManualResetEvent / WaitOne
First - I don't know a great deal about the shell messages in
question, so this only covers general principal...
I think part of the problem is that blocking the UI thread is never a
good idea.
Would it be possible to simply disable the UI (i.e. set .Enabled =
false on a few strategic controls), do the waiting on a pool thread,
and then call-back (Control.Invoke) onto the UI thread to wake it all
back up and re-enable the UI?
Alternatively, Application.DoEvents() exists, which should allow it to
process enough of the message-queue to get your external messages -
but you can't really predict what messages it is going to handle doing
this. I would tend to use the first approach if possible.
Marc
Date:Thu, 23 Aug 2007 13:53:58 +0100
Author:
|
Re: ManualResetEvent / WaitOne
Hi Marc,
Shell events don't differ from invoking to the GUI thread.
What i don't understand is that while blocking the GUI thread, the GUI
thread decides to continue somewhere else. And i'm not talking about holding
the thread for a long time of periode, WaitOne(0, true) would also raise
this issue.
/Peter
Date:Thu, 23 Aug 2007 15:26:03 +0200
Author:
|
Re: ManualResetEvent / WaitOne
Ahah! it becomes clearer... I read the line (below) as "this is what I
want to achieve", rather than "this is darned freaky, why is it
happening?"
> How is it possible to receive the second event while blocking the
> GUI thread ??
Yes, that is odd... are you sure that it is actually the GUI thread
that is invoking? It could be the shell events are arriving on an
arbitrary thread? Worth checking the ManagedThreadId in the GUI code,
and in the method that is being triggered... are they
one-and-the-same?
Marc
Date:Thu, 23 Aug 2007 14:47:07 +0100
Author:
|
|
|