EventWaitHandler

C

crino

Hi,
i need to run a function at a specific time to switch the status of my
application.
I tried the code suggest by Peter but the EventWaitHandler.WaitOne()
didn't works properly....the function is raised immediately!?

Any clue??
Thanx in advance ;)
this is my code:

private bool bAppExit = false;
private EventWaitHandle notifyStartEvent = null;
private OpenNET.Threading.ThreadEx threadStart = null;

public void ThreadProcStart()
{
SystemTime nextrun = GetNextDate(short.Parse(cboInitH.Text),
short.Parse(cboInitM.Text));
DateTime runtime = nextrun.ToDateTime();
// Create event for notification.
notifyStartEvent = new OpenNET.Threading.EventWaitHandle(false,
OpenNET.Threading.EventResetMode.AutoReset,
"CallStartEvent" );
// Set up notification.
Notify.RunAppAtTime(
"\\\\.\\Notifications\\NamedEvents\\CallStartEvent", runtime );
// Wait for the notification event to fire.
notifyStartEvent.WaitOne();
// Let the notification subsystem know that it's
// done with the event.
try
{
Notify.RunAppAtTime(
"\\\\.\\Notifications\\NamedEvents\\CallStartEvent", DateTime.MinValue
);
}
catch//(Exception ex)
{
}
// Close event handle.
notifyStartEvent.Close();
// If the event was fired because the application
// is exiting, do nothing else; just return.
if ( !bAppExit )
{
// Notify the user that the event fired.
this.Invoke( new EventHandler(ChangeState));
}
// Clear thread to indicate that we're done.
threadStart = null;
}


Thanx in advance
 
G

Guest

First, post the actual code. There are several syntax errors in what you've
posted (like it's OpenNETCF, not OpenNET and we have no ThreadStart), so I
know it won't run. Second, what is the value of 'nextrun'? Did you try it
using Now with a timespan of say 30 seconds added?

-Chris
 
P

Paul G. Tobey [eMVP]

Well that code does work, in general. Most likely, whatever you are doing
to calculate when to fire the event is responsible. Set the target time to
5 minutes into the future and verify, in that case, whether the event is set
initially or not. If you ask for an event that is close enough to the
current time that it's within the resolution of the alarm, the event is set
immediately.

Paul T.
 
C

crino

I tried the sample application.....but, i repeat, the event start
immediatly...also if i set 5 minutees delay!?
In my app i set the event the day after....and it's fired immediatly :(
 
P

Paul G. Tobey [eMVP]

I don't know what to tell you. I just ran it, too, and it works perfectly,
right out of Vault. Make sure that you are creating an event name of the
right format. In fact, just use the source *exactly* as it is in the source
control system. You're compiling the latest OpenNETCF source, too, right?
How are you triggering the wait in the sample? What value in the edit box?
Which radio button? Have you stepped into the various calls that occur to
OpenNETCF methods in the thread to make sure that they look reasonable?

Paul T.
 
C

crino

Paul, Peter can i send you my example app?

thanx in advance ;)

ps: i tried to post here the attachment but the server had locked it!?
......i belive
 
P

Paul G. Tobey [eMVP]

Just use the sample code directly from OpenNETCF. It's a known-good
starting point. If it works, then you can proceed from there. If it
doesn't work, we need to look at your hardware and the OS running on it.

Paul T.

crino said:
Paul, Peter can i send you my example app?

thanx in advance ;)

ps: i tried to post here the attachment but the server had locked it!?
.....i belive



Paul G. Tobey said:
I don't know what to tell you. I just ran it, too, and it works
perfectly, right out of Vault. Make sure that you are creating an event
name of the right format. In fact, just use the source *exactly* as it is
in the source control system. You're compiling the latest OpenNETCF
source, too, right? How are you triggering the wait in the sample? What
value in the edit box? Which radio button? Have you stepped into the
various calls that occur to OpenNETCF methods in the thread to make sure
that they look reasonable?

Paul T.

crino said:
I tried the sample application.....but, i repeat, the event start
immediatly...also if i set 5 minutees delay!?
In my app i set the event the day after....and it's fired immediatly :(



"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
ha scritto nel messaggio Well that code does work, in general. Most likely, whatever you are
doing to calculate when to fire the event is responsible. Set the
target time to 5 minutes into the future and verify, in that case,
whether the event is set initially or not. If you ask for an event
that is close enough to the current time that it's within the
resolution of the alarm, the event is set immediately.

Paul T.

hi ctacke,
sorry the namespace is OpenNETCF ;)

the nextrun value change everytime the function calculates the new
time
with the arguments :)

i get the code from:
http://vault.netcf.tv/VaultService/VaultWeb/login.aspx in
'Sample/Notification'
but this application too didn't works correctly !?!

ps: the code is compiled correctly
 
C

cseverini

so....
i've installed Vault client and re-downloaded the Notification example,
re-compilated the solution and
both in emulator and in my Qtek S100 (jam i-mate ...) the function is
raised immediatly :(
During the debug the code goes on even WaitOne().....i think that this
function has to wait the event is fired rigth?
instead the code call WaitOne and goes on immediatly so the function is
called :(
Please help me .... i can't continue my application without this
feature :(

if you want you can send me the version which works to you (source and
exe).
Thanx again


ps: http://www.pocket.at/ppc3/htcm.htm here you can find all my
hardware spec ;)
 
P

Peter Foot [MVP]

If you have SDF v1.2 installed on your development machine you may have
problems since this sample relies on functionality added since v1.2 - which
is why you need the latest source from the vault. Try renaming all the
OpenNETCF.*.dlls in C:\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows CE and then deploy Paul's sample
application. All being well this should deploy the v1.3 versions and work
correctly.

Peter
 
D

Daniel Moth

This is a long shot but just in case...

When you step into the EventWaitHandle class, scroll down to the private
ctor taking aHandle as the only parameter. Does it look like this:
private EventWaitHandle(IntPtr aHandle):base(){
if (aHandle.Equals(IntPtr.Zero)){
throw new ApplicationException("CreateEvent failed");
}
this.Handle = aHandle;
}
...or like this:
private EventWaitHandle(IntPtr aHandle):base(){
if (aHandle.Equals(IntPtr.Zero)){
throw new ApplicationException("CreateEvent failed");
}
this.Handle = Handle;
}

If it is the latter, I don't know how you managed to get that version (I
fixed it soon after the source was added to the vault), but getting the
latest source (like everybody has been suggesting) will fix it for you. If
you've got the former, ignore this post completely.

Cheers
Daniel
 
G

Guest

seems i've an old version of EventWaitHandle class !?

i searched the line told by Daniel and changed it....and now seems
works.....finally!

thanx!!!!
 
C

crino

The EventWaitHandle works....but now i have some problems with the
threads:(

I start the first thread, like in example code....and if i wait the
notification all works:
the 'Notify_Fired' event is raised and then i can exit from application
without problems

my problem is that i would change the time of programmed event during
the thread is running.
I tried to execute the following code but Set() method is raised at the
end of my function so i loss a Thread in memory (i think) so when i try
to exit from the app it didn't exit

My code to re-program the time:

private void NewTime
{
if (thread != null){
notifyeventhandler.Set();
notifyeventhandler.Close();
}

thread = new OpenNETCF.Threading.ThreadEx(new
ThreadStart(ThreadProcStart));
thread.Start();
}
 
P

Paul G. Tobey [eMVP]

No, you lost me. What are you trying to accomplish? Setting a new
notification time? Cancelling the current one? What?

Paul T.
 
C

crino

Paul thanx but i fixed it ;))
I reuse always the same thread and reset the new time calling
Notify.RunAppAtTime with new time :)

thanx for all

bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top