Re: Mobile Service & Auto Start



I've replied on the registry and error code finding to the last message
because I didn't want those points to get lost...

Are you sure you *closed* your application? Remember that, on Windows
Mobile devices, the X box on the title bar *does not close the application*.
It minimizes it (called Smart Minimize, if you want to search the archives
for info).

As I mentioned in my original description of how I'd handle this, you might
want to have CeRunAppAtTime() fire an event, not launch a program.
OpenNETCF has a class library for doing that. Check the Notify class. It's
in the Smart Device Framework 1.4, I know. Ah, here's the sample I wrote
for firing an event at a time. I'll copy it below and hopefully it won't be
overly long...

Whoops, you started too close to the deadline! Always allow several months
for understanding a completely new technology! You'll hardly ever be wrong.

Paul T.

----

code for form1.cs from notification sample of OpenNETCF. You need Smart
Device Framework (open source), 1.4 to use it.

/// This Notification sample uses the Notification Manager in Windows CE.NET
/// and later to notify the application that a given time of day has been
/// reached via an event, rather than by launching the application, as the
/// older version OSes will do. For this, you create a named event, call
/// CeRunAppAtTime() with a very special application name parameter (and the
/// time at which the notification should fire, of course).

namespace Notification
{
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using OpenNETCF;
using OpenNETCF.Drawing;
using OpenNETCF.Windows.Forms;
using OpenNETCF.Win32;
using OpenNETCF.Win32.Notify;
using OpenNETCF.Threading;
using System.Threading;

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private OpenNETCF.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton HoursRadio;
private System.Windows.Forms.RadioButton MinutesRadio;
private OpenNETCF.Windows.Forms.TextBoxEx DelayTimeEdit;
private System.Windows.Forms.Button GoButton;

private OpenNETCF.Threading.ThreadEx thread = null;
private bool appExiting = false;
private int delay = 1;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

// 1.3-based stuff.
this.DelayTimeEdit = new OpenNETCF.Windows.Forms.TextBoxEx();
this.DelayTimeEdit.Style = OpenNETCF.Windows.Forms.TextBoxStyle.Numeric;
this.groupBox1 = new OpenNETCF.Windows.Forms.GroupBox();
//
// DelayTimeEdit
//
this.DelayTimeEdit.Location = new System.Drawing.Point(8, 33);
this.DelayTimeEdit.Size = new System.Drawing.Size(104, 20);
this.DelayTimeEdit.Text = "5";
// groupbox1
this.groupBox1.Location = new System.Drawing.Point( 120, 25 );
this.groupBox1.Size = new System.Drawing.Size(110, 60);
this.groupBox1.Text = "Units";
this.groupBox1.Controls.Add( this.MinutesRadio );
this.groupBox1.Controls.Add( this.HoursRadio );
// form
this.Controls.Add( this.DelayTimeEdit );
this.Controls.Add(this.groupBox1 );
}
/// <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.label1 = new System.Windows.Forms.Label();
this.HoursRadio = new System.Windows.Forms.RadioButton();
this.MinutesRadio = new System.Windows.Forms.RadioButton();
this.GoButton = new System.Windows.Forms.Button();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Size = new System.Drawing.Size(184, 20);
this.label1.Text = "Delay before notification:";
//
// HoursRadio
//
this.HoursRadio.Location = new System.Drawing.Point(16, 16);
this.HoursRadio.Size = new System.Drawing.Size(88, 16);
this.HoursRadio.Text = "Hours";
//
// MinutesRadio
//
this.MinutesRadio.Checked = true;
this.MinutesRadio.Location = new System.Drawing.Point(16, 40);
this.MinutesRadio.Size = new System.Drawing.Size(88, 16);
this.MinutesRadio.Text = "Minutes";

//
// GoButton
//
this.GoButton.Location = new System.Drawing.Point(96, 112);
this.GoButton.Text = "Go";
this.GoButton.Click += new System.EventHandler(this.GoButton_Click);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(250, 143);
this.Controls.Add(this.GoButton);
this.Controls.Add(this.label1);
this.Text = "Notification Sample";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.Form1_Closing);

}
#endregion

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

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

private void GoButton_Click(object sender, System.EventArgs e)
{
// The user has triggered the delay. First, calculate
// when the notification will be fired, then set
// up an event to be triggered by the notification,
// then fork off a thread to wait for the notification.
// When the notification is fired, the thread
// will invoke a method to show a dialog and exit,
// returning us to the idle state.
delay = Int32.Parse( DelayTimeEdit.Text );
if ( HoursRadio.Checked )
{
delay *= 60;
}

// Delay is now in minutes.

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

public void Notify_Fired(object sender, System.EventArgs e)
{
// The notify event fired. Notify the user.
MessageBox.Show( "The notification has fired.",
"Notification" );
}

public void ThreadProc()
{
// The thread procedure simply waits for the
// notification event to fire (or for the main
// application thread to set it, because it's
// time to leave the thread).

// Figure out when.
DateTime runtime = DateTime.Now;
runtime = runtime.AddMinutes( delay );

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

// Set up notification.
Notify.RunAppAtTime(
"\\\\.\\Notifications\\NamedEvents\\OpenNETCFSampleNotifyEvent", runtime );

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

// Let the notification subsystem know that it's
// done with the event.
try
{
Notify.RunAppAtTime(
"\\\\.\\Notifications\\NamedEvents\\OpenNETCFSampleNotifyEvent",
DateTime.MinValue );
}
catch( Exception e )
{
}

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

// If the event was fired because the application
// is exiting, do nothing else; just return.
if ( !appExiting )
{
// Notify the user that the event fired.
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 )
{
EventWaitHandle notifyEvent = new OpenNETCF.Threading.EventWaitHandle(
false,
OpenNETCF.Threading.EventResetMode.AutoReset,
"OpenNETCFSampleNotifyEvent" );

// Notify the thread to stop.
notifyEvent.Set();

notifyEvent.Close();
}
}
}
}


.


Quantcast