![]() |
|
QA: How can I register my program to run at a certain time?
By Evan Golub, February 20, 2002.
QuestionI would like to set it so that my program launches itself at some later time (even if my PocketPC is turned off). Can I do this and how? AnswerYes, you can register an application to be run at some later time. Yes, if your PocketPC is turned off at that time, it will turn on to run your application. The API call you want is CeRunAppAtTime. This function will take the name of an application and the time you want to run that application. eMbedded Visual BasicFirst, you will need to add the following to the top of your code to be able to call the function: Next, you need to build a String that contains a SYSTEMTIME. Since embedded Visual Basic does not have user-defined types, you'll need to assemble it "by hand". Fortunately, someone else has already created some very useful functions to do this. The following two functions are from and article by Antonio Paneiro:
You can now call SYSTEMTIME with the individual values (eg: year, month, etc.) and get back a String that is formatted correctly for use by the CeRunAppAtTime function. For example, say you wanted to allow a user of your program to press a button and have your program start again tomorrow at the same time of day that it currentlt is. You could add the following to a button's Click method: The above code will build a SYSTEMTIME formatted date that is the current time of day, but tomorrow rather than today and schedule your application to be run at that time. Note that by using the DateAdd function, you do not have to concern yourself with sepcial cases such as the last day of the month - the function deals with those for you. If the program that you have scheduled to execute is already running, it will be brought to the foreground if it is not already there. eMbedded Visual C++CeRunAppAtTime function is defined in the Notify.h header. Use GetModuleFileName function to get full path of the current application. You code can be like: When it is necessary the system will start your application and will pass the APP_RUN_AT_TIME string as the command line. If your application is MFC based and one copy is already running then your running copy will be just brought to the foreground. But because the command line is not passed from the started copy to the running copy (MFC does not implement it) you will not be able to understand if the event happend.
To solve this problem you can make a "launcher" application that will start
your main application if it is not running yet and will send some custom window
message. Read more at: Change/RemoveIf you wish to change the time at which an application should be run, simply call CeRunAppAtTime again with the executable's path and name and the new execution time. This will delete the existing entry and create a new one with this new time. If you wish to cancel a scheduled event, you can call CeRunAppAtTime with the executable path and name of the program that is to be executed, but pass 0 as the new execution time. This will remove the previous request entry and will not create a new one. After an event has occurred, it will be removed from the system's list of execution requests. Related resources:
DiscussDiscuss this article. Here you can write your comments and read comments of other developers. |
|||||||||||||||||||||