Re: Mobile Service & Auto Start
- From: "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT com>
- Date: Tue, 2 Jan 2007 09:18:26 -0700
No, CeRunAppAtTime() should work in the emulator, for whatever that's worth;
remember that it's an API for setting reminders, not a real-time call, so it
might be off by 30 seconds, depending on what else is going on. Maybe your
SYSTEMTIME is declared wrong. Or maybe you're passing GMT rather than local
time?
Other than that, you'd have to be sure that the application is not still
running, as I said (if calc is already running, a second copy won't be
started). I've never had any problems with the call on real devices. The
only thing funny about it to me is the syntax for the "application name"
when you want to have it fire an event, not start an application.
Paul T.
"Jeremy" <Jeremy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3D133A49-A72C-439A-B657-1B4D62D88AD5@xxxxxxxxxxxxxxxx
So I am guessing that the call just doesnt work in the emulator, I finally
deployed my solution to my PDA and it worked. Thanks everyone for all of
your
help!
"Jeremy" wrote:
Oh I did have something to check for errors it was like:
if (!CeRunAppAtTime(SystemInfo.AppName, ref sysTime)) {
Win32Exception ex = new
Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
MessageBox.Show("Error: "+ex.Message+" "+ex.ErrorCode+"
"+ex.NativeErrorCode);
}
It always returns true
"<ctacke/>" wrote:
Your assumption is incorrect. Once the notification is set, the app
can
close an it should still execute as expected. What I'm not seeing is
you
checking the return from CeRunnAppAtTime to see if an error occurred.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--
"Jeremy" <Jeremy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:549026C3-FCE4-4EEA-9BC0-6158FEE0CDCD@xxxxxxxxxxxxxxxx
First off let me say I really appreciate your help, usually I post on
msdn
and 6 weeks later someone gets back to me with something I already
figured
out.
Now I have written quite a few mobile device apps, including a lot of
apps
that do pinvoke calls, but as I mentioned it does always seem like a
pain
to
find any good info on the pinvoke calls when they are needed. up till
now
I
have never needed to write an app like this and I just figured since
i
have
written Windows Services before that do certain things at certain
times,
or
because of certain events that it would not be difficult. Boy I was
wrong.
The init thing works great, I just played with what exe inits in what
order
and that works out good for me with an implementation to unlock a
service
from accessing a file and i knew I could always copy in the contents
of
pim.vol from one file from another based on each individual value I
just
wanted to make it easy on myself.
Now as for this CeRunAppAtTime or
OpenNetCF.WindowsCE.Notification.NotifyRunAppAtTime which are
technically
both exactly the same by sending the app location and the SYSTEMTIME
struct,
the only difference being is theres converts the datetime object
where
mine
expects the SYSTEMTIME struct.
Now just that you do understand I do kinda know what I am doing, I am
really
just very dumb about the CeRunAppAtTime call and why it may not work.
So I have an exe that I start 5 min after I push a button. Now for
SAG I
use
calc.exe
and that didnt work either just to see if there was a problem with
open my
exe.
I have:
[DllImport("coredll.dll", SetLastError=true)]
internal static extern bool CeRunAppAtTime(string appName, ref
SYSTEMTIME
time);
and a SYSTEMTIME struct.
and i call
CeRunAppAtTime(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase,
SYSTEMTIME.FromDateTime(DateTime.Now.AddMinutes(5));
Application.Exit();
----The above does nothing----
So this is what I am getting fom what you posted. CeRunAppAtTime
doesnt
allow you to run an exe at a later time? I need it to run even if my
app
has
closed ( a real close using Application.Exit() not a minimize ) So I
would
have to thread an exe that does nothing but define an event, then I
could
run
CeRunAppAtTime to execute an event within that exe which is running
in the
background.
Is this correct?
This is one of the most confusing calls I have ever encountered, what
I
want
is a call that says
Execute "FileName.exe" at "DateTime" no matter what is going on.
Let me know if I am correct in my assumption of what you posted.
Thank you again!
"Paul G. Tobey [eMVP]" wrote:
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();
}
.
- Follow-Ups:
- Re: Mobile Service & Auto Start
- From: Jeremy
- Re: Mobile Service & Auto Start
- References:
- Re: Mobile Service & Auto Start
- From: Jeremy
- Re: Mobile Service & Auto Start
- Prev by Date: Re: Storage card browsing fails
- Next by Date: Re: Word Object Model
- Previous by thread: Re: Mobile Service & Auto Start
- Next by thread: Re: Mobile Service & Auto Start
- Index(es):
Loading