Run function at time

C

crino

Hi at all!
I would like to run a function in my app at predefinite time?
There is a way to do it??

Like CeRunAppAtTime but i've to run a function :)

Thanx in advance
 
C

crino

Thanx for your reply Peter ;)
There is a way to set the notification periodically? (ex: all sunday at 8
PM)

thanx in advance ;))
 
P

Peter Foot [MVP]

Probably the best way is to queue up the next notification each time the
event is raised, e.g. use DateTime.Today.AddDays(7) to get the date for a
week ahead.

Peter
 
C

crino

Hi Peter,
i tried the code in my application....but the event is raised immediately!?!
Any clue??
 
G

Guest

I did have problems with the event raising right away if my timeout was < 18
seconds. But once I set it for longer it worked (I used a 1 minute wait time).

The notification fired as planned when I turned the unit off and waited the
1 minute time frame. Then it would fire the event as desired. However, if I
turned the unit back on before the 1 minute was up then the event
notification never fires. I tried making the event longer and it made no
different. Once I toggled to Off and back On the event will never fire. The
thead is still running as indicated by the thread.State value.

Anyone have an idea why a unit would cancel the notification?
 
P

Paul G. Tobey [eMVP]

Yes, you shouldn't be using CeRunAppAtTime for things in that range. It's
not a seconds-resolution timer; it uses the alarm capability of the
real-time clock in the processor.

I have no idea why *suspending* the unit would stop the notification. You
are *suspending* it, *not* turning it off, right? We need you to be precise
in your descriptions or our time is wasted. Since I don't see the rest of
the thread here, what hardware is this, again?

Paul T.
 
G

Guest

I was not trying to use it as a second resolution - I was responding to
"crino's" post about it firing right away. As far as the equipment goes I've
been trying to get this to work on an HHP 9500 with PPC2003 as well as the
HHP 7900 with PPC2003 SE all with SP2 of the CF.NET.

My application requires the user to press a Batch Refresh button in my
application that starts the thread and notification process so as to wake the
unit up between 2 am and 6 am (users choice).

I don't believe the off button on the unit turns off anything but the screen
and is infact putting the unit in suspend or sleep mode. Notification works
as long as I either leave it running by providing power to the unit and
setting the power mode to remain on as long as there is external power (unit
never sleeps), or by turning it off and leaving it off until the Notification
fires (in which case the call back function turns the screen on and does what
I need it to do).

The problem occurs for not firing the Notification when the customer turns
the unit off and then back on a few minutes later then off again, etc.

I used the exact program that I got from Peter's posting:
CeRunAppAtTime can also be ... specified time. See Paul Tobey's example in
the vault:-http://vault.netcf.tv/VaultService/VaultWeb/login.aspx
(Username: guest Password:guest)
Browse to $/Samples/Notification
 
P

Paul G. Tobey [eMVP]

Great! I think that you've done everything reasonable in that situation.
Are there other reminder or calendaring programs on the device that come
from the device OEM that exhibit the same problem? Where I'm going with
this is that I think that the device OS is broken, so you need to approach
the OEMs and say, "Look, your program doesn't work in this scenario". If
their calendar program fails, too, they have everything they need to
duplicate it and it should be easier to get a fix.

I seem to recall some discussion somewhere about problems with alarms on
some devices in some situations, but I can't remember exactly what the
symptoms were or where I saw it. I'd see if you can approach the OEM this
way, though...

Paul T.
 
C

Chris Tacke, eMVP

PPC2003 has known issues with CeRunAppAtTime and if you look in the platform
header (notify.h specifically) you'll see it's marked as deprecated. Try
using CeSetUserNotification instead.


--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
G

Guest

After switching over to use the CeSetUserNotication it still exhibits the
same problem. I did some looking and found a company called ScaryBear
software that has a free application to check queued Notications. This tool
shows me that my notication makes it and it does fire as long as I never turn
off and then turn back on the hand held unit (HHP Dolphin 9500 with PPC 2003,
CF SP2). The Notification event never fires for test program. I can then exit
my program and when I try to re-run it, it will fire right away because of
the left over Notication is still pending from my previous run. You have to
either soft boot the unit or remove it with a tool.

Here is a sample program set up to run in 1 minute. Feel free to modify it.

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Threading;

using OpenNETCF.Win32.Notify;
using OpenNETCF.Threading;

namespace TimerTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.MainMenu mainMenu1;

private OpenNETCF.Threading.EventWaitHandle notifyEvent = null;
private OpenNETCF.Threading.ThreadEx thread = null;

private bool appExiting = false;
private int handle;

public Form1()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.btnStart = new System.Windows.Forms.Button();
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(80, 32);
this.btnStart.Text = "Start";
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// Form1
//
this.Controls.Add(this.btnStart);
this.Menu = this.mainMenu1;
this.MinimizeBox = false;
this.Text = "Notify It";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.Form1_Closing);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>

static void Main()
{
Application.Run(new Form1());
}

public void Notify_Fired(object sender, System.EventArgs e)
{
MessageBox.Show("Event has fired");
}

private void btnStart_Click(object sender, System.EventArgs e)
{
// Allow to start only once
btnStart.Enabled = false;

// Create event for notification.
notifyEvent = new OpenNETCF.Threading.EventWaitHandle
(false, OpenNETCF.Threading.EventResetMode.AutoReset, "TimerTest");

// Start thread to monitor event.
thread = new OpenNETCF.Threading.ThreadEx( new ThreadStart(
this.ThreadProc ) );
thread.Start();
}

public void ThreadProc()
{
// Figure out when.
DateTime runtime = DateTime.Now;
runtime = runtime.AddMinutes( 1.0 ); // 1 minute delay

// Set up user notication object with default settings.
OpenNETCF.Win32.Notify.UserNotification userNotify = new
OpenNETCF.Win32.Notify.UserNotification();

// Call the static routine with a future date offset
handle =
Notify.SetUserNotification("\\\\.\\Notifications\\NamedEvents\\TimerTest",runtime,userNotify);

// Wait for the notification event to fire.
notifyEvent.WaitOne();

// Call the static routine to clear the notification.
Notify.ClearUserNotification(handle);

// Close event handle.
notifyEvent.Close();

if (!appExiting)
{
this.Invoke( new EventHandler( Notify_Fired ) );
}

// Clear thread to indicate that we're done.
thread = null;
}

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// When we're ready to leave, we have to be sure
// that we don't leave any threads running.
appExiting = true;

if (thread != null)
{
// Notify the thread to stop.
notifyEvent.Set();
notifyEvent.Close();
}
}
}
}
 
P

Paul G. Tobey [eMVP]

When the program exits, it should stop any active notifications that it sets
up and has not yet received.

Paul T.
 
G

Guest

I did figure that out by the time I copied my example program to the previous
posting. I had to add the line that calls the ClearUserNotication when the
thread is told to stop processing. This did clear up the issue where
notifcation occurs immediately following the request for Notification.

I know this is a big issue for lots of developers and so I really am trying
to get to the bottom of this (i.e. a solution that is consistent). So in my
continued research I've discoverd the following tidbit. Once you turn the
hand held unit off then back on again the event will not fire - unless you
plug the unit back in to the active sync cable - this of course starts up
active sync connection and immediately the test programs event fires.

Thus, I have created a duplicatable issue on my HHP units (PPC2003 and 2003
SE). I will now test on a Symbol 81xx series using PPC2002. If anyone has any
idea to why this maybe happening I would like to know - for now I'm thinking
of adding additional code to my application to catch the power on button;
cancel previous notification request and re-request a new one each time they
power on and off the units (this is need because my customers use Wireless to
pull data from a webservice and never activesync up to a PC).
 
S

Steve Maillet \(eMVP\)

CeRunAppAtTime and CeSetUserNotification ultimately go to the same place
underneath and both have the same limitations that are ultimately device
dependent. In general you cannot use those APIs to set a notification less
then 10 seconds into the future.
 

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