locked
how can i make auto execution of project RRS feed

  • Question

  • Hi to all,
             I have made one application on windows mobile. I want to call this application automatically with in a certain time of period. How can i do this. I have checked for "Timer" class but its not supporting in compact framwork.
    Can any body help me out ?

    Thanks in advance...
    Thursday, September 10, 2009 9:09 AM

Answers

    • Marked as answer by warrentang Monday, September 14, 2009 7:36 AM
    Thursday, September 10, 2009 9:31 AM
  • Hi Rishabh,
    Take a look at CeRunAppAtTime method:
    http://msdn.microsoft.com/en-us/library/aa931253.aspx

    Regards,
    Pawel
    • Marked as answer by warrentang Monday, September 14, 2009 7:36 AM
    Thursday, September 10, 2009 9:33 AM
  • As Pawel said you want to take a look at CeRunAppAtTime.

    from http://www.codeproject.com/KB/mobile/WiMoAutostart.aspx

    The Windows CE / Windows Mobile OS contains functionality for automatically starting a program at a specified time. The functionality is available through a call to CeRunApAtTime from the CoreDLL library. As mentioned by Jim Wilson in many of his “How Do I” video posts on MSDN, this function expects the start time to be specified in the WinAPI SystemTime structure instead of the DateTime structure (CeRunAppAtTime is an unmanaged function called using the platform invoke functionality). Converting a time from a DateTime to a SystemTime is not difficult; there are WinAPI functions that doed this for you. To make calling this function easier, I have placed the following code in my Win32Helper class. I’ve also provided an overloaded function to allow the time to be passed as an offset from the current time with a TimeSpan object.
    public static void RunAppAtTime(string applicationEvent, DateTime startTime)
    {
        long fileTimeUTC = startTime.ToFileTime();
        long fileTimeLocal = 0 ;
        SystemTime systemStartTime = new SystemTime();
        CoreDLL.FileTimeToLocalFileTime(ref fileTimeUTC, ref fileTimeLocal);
        CoreDLL.FileTimeToSystemTime(ref fileTimeLocal, systemStartTime);
        CoreDLL.CeRunAppAtTime(applicationEvent, systemStartTime);
    }
    public static void RunAppAtTime(
         string applicationEvent, 
         TimeSpan timeDisplacement
    )
    {
        DateTime targetTime = DateTime.Now + timeDisplacement;
        RunAppAtTime(applicationEvent, targetTime);
    }

    applicationEvent is the full path to the application to start and startTime is the time at which the application should be executed. There’s also an overloaded version of the method that accepts a TimeSpan object instead of a DateTime, if you want to specify the start time relative to the current time.

    If an application were attempting to schedule itself to be restarted at a later time, it will need to be able to pass its complete path. I used Reflection to find that path.

    Module[] m = this.GetType().Assembly.GetModules();
    target = m[0].FullyQualifiedName;

    Joel Ivory Johnson
    • Marked as answer by warrentang Monday, September 14, 2009 7:36 AM
    Thursday, September 10, 2009 12:15 PM

All replies

    • Marked as answer by warrentang Monday, September 14, 2009 7:36 AM
    Thursday, September 10, 2009 9:31 AM
  • Hi Rishabh,
    Take a look at CeRunAppAtTime method:
    http://msdn.microsoft.com/en-us/library/aa931253.aspx

    Regards,
    Pawel
    • Marked as answer by warrentang Monday, September 14, 2009 7:36 AM
    Thursday, September 10, 2009 9:33 AM
  • As Pawel said you want to take a look at CeRunAppAtTime.

    from http://www.codeproject.com/KB/mobile/WiMoAutostart.aspx

    The Windows CE / Windows Mobile OS contains functionality for automatically starting a program at a specified time. The functionality is available through a call to CeRunApAtTime from the CoreDLL library. As mentioned by Jim Wilson in many of his “How Do I” video posts on MSDN, this function expects the start time to be specified in the WinAPI SystemTime structure instead of the DateTime structure (CeRunAppAtTime is an unmanaged function called using the platform invoke functionality). Converting a time from a DateTime to a SystemTime is not difficult; there are WinAPI functions that doed this for you. To make calling this function easier, I have placed the following code in my Win32Helper class. I’ve also provided an overloaded function to allow the time to be passed as an offset from the current time with a TimeSpan object.
    public static void RunAppAtTime(string applicationEvent, DateTime startTime)
    {
        long fileTimeUTC = startTime.ToFileTime();
        long fileTimeLocal = 0 ;
        SystemTime systemStartTime = new SystemTime();
        CoreDLL.FileTimeToLocalFileTime(ref fileTimeUTC, ref fileTimeLocal);
        CoreDLL.FileTimeToSystemTime(ref fileTimeLocal, systemStartTime);
        CoreDLL.CeRunAppAtTime(applicationEvent, systemStartTime);
    }
    public static void RunAppAtTime(
         string applicationEvent, 
         TimeSpan timeDisplacement
    )
    {
        DateTime targetTime = DateTime.Now + timeDisplacement;
        RunAppAtTime(applicationEvent, targetTime);
    }

    applicationEvent is the full path to the application to start and startTime is the time at which the application should be executed. There’s also an overloaded version of the method that accepts a TimeSpan object instead of a DateTime, if you want to specify the start time relative to the current time.

    If an application were attempting to schedule itself to be restarted at a later time, it will need to be able to pass its complete path. I used Reflection to find that path.

    Module[] m = this.GetType().Assembly.GetModules();
    target = m[0].FullyQualifiedName;

    Joel Ivory Johnson
    • Marked as answer by warrentang Monday, September 14, 2009 7:36 AM
    Thursday, September 10, 2009 12:15 PM
  • Hi thanks to all for your replies........

    I have one issue, i need to schedule only a method in the existing application.

    I want call a perticular function after application execute first time. How can i do this  ?
    What i have to put in the place of "applicationEvent" in above code.


    Thanks
    Rishabh
    Thursday, October 15, 2009 5:51 AM
  • Create as static function and call in your app "main" function.

    -Siva. * Please mark as answer and vote if my post help to fix your issue.*
    Thursday, October 15, 2009 8:23 AM
  • Hi GSiva thanks for reply,

    How can i call my method after some perticular time by making  static function.
    can you explain me or give give me any sample example ?

    Thursday, October 15, 2009 9:43 AM
  • applicationEvent should contain in this case a path to your executable (it can contain other things too, but I won't get into that).  You'll need to save information to a file or the registry so that when your programs tarts it can see what it is supposed to do.
    Joel Ivory Johnson
    Thursday, October 15, 2009 12:09 PM