views:

25

answers:

2

Hello,

In my project, I want to catch some named event from the system, like "IDH/Presence" or "IDH/AmbiantLight".

How can I do that ?

Edit: Is that possible with the EventWaitHandle class of the Smart Device Framework ?

Thanks.

+1  A: 

I am not familiar with the functionality you refer to in the SDF (ctacke will probably answer that). But, to wait on a named event handle you simple call CreateEvent with the name and wait on the handle that is returned.

Be aware that in case the event is auto reset, only one WaitForSingleObject call will catch it and then it will be reset so if other threads are waiting on the same handle you might not catch the event.

Shaihi
It work fine with a while(true) for catch whenever that the named event is raised.Is there a more elegant way to do this ?
Jérémie Bertrand
I didn't get your usage. Can you post code? The elegant way to wait on an event is `WaitForSingleObject`/`WaitForMultipleObjects` (http://msdn.microsoft.com/en-us/library/bb202783.aspx). This is the correct way to work with events, otherwise you miss the whole point of event driven system.
Shaihi
The same named event can be raised multiple times.So I have a thread which wait for this event.Without while(true) only the first event is catched.
Jérémie Bertrand
That is the correct way to handle it. However, why do you keep opening and closing the handle> Move the open before the while(true) and the close when you break out of it.
Shaihi
Ok, thank you very much !
Jérémie Bertrand
+1  A: 

The CF itself doesn't provide the ability to use named system events.

The SDF's EventWaitHandle does provide the capability by using either of the constructors that allow for the name parameter.

The other option is to P/Invoke CreateEvent and WaitForSingle/WaitForMultipleObjects.

ctacke