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();
}
}
}
}