Posts tagged ‘periodically’

Windows Mobile – tasker2 runs and stops applications periodically

Tasker2 is a tool to launch or kill applications periodically using windows mobile scheduler. It was born to control the running of agent software on windows mobile at specified times. The problem with the agent software was that it does not open/close connections only on usage times but all the time and the device’s battery was drain very fast. We decided to write a helper that would launch and kill the agent to have it running only within a defined time frame.

Background process

We could have written a background process to run external tasks periodically. But the main disadvantage of timers and threads in background processes is that they do not run, if the device is in suspend mode.
To ensure that tasks will be launched also if the device is sleeping, we decided to use the windows mobile scheduler. There are functions inside the notification API to create notifications that will run an application at a specified time. This is what we call a schedule.

The scheduler (notification API)

After a timed schedule has been done by the scheduler, the schedule is removed from the notification database. If you like to have a periodic schedule, you have to ensure that a new schedule is created inside your code.

Pitfalls

During development we found many pitfalls in conjunction with the windows mobile scheduler. This is why I decided to write this post.

The tasks

Tasker2 is a console application without any GUI but it will write a log with all you need to know. Tasker2 supports up to ten tasks. A task is defined using the registry. Every task has an entry for start and stop times, the application to control, an interval for the schedule and a flag for control if a task is only to be run on external power:

REGEDIT4

[HKLM\Software\Tasker\Task1]
"active":DWORD=1
"exe":="\Windows\fexplore.exe"
"arg":="\My Documents"
"start":="1423"
"stop":="1523"
"interval":="2400"
"startOnAConly":DWORD=0;

active: if active is 0, tasker2 will not kill or start the process
exe: name of the process executable to start or kill
arg: arguments to be when launching the executable
start: when to start the executable the next time
stop: when to kill the process the next time
interval: when a start or kill has been executed, tasker2 will create a new schedule using this interval. If the interval is “0010”, the start process will be scheduled for every 10 minutes.
startOnAConly: if 1 and when a process has to be started, the process will only be started if the device is on external power

The scheduler

First, tasker2 is normally only launched one time manually and all future calls are made by the scheduler. Tasker2 will clear and schedule all planned tasks as defined in the registry if it is launched without arguments.

Continue reading ‘Windows Mobile – tasker2 runs and stops applications periodically’ »

Howto run an application periodically

Hello

for some reason you might want to rerun an application very day or every hour. In commercial applications, one may want to let the device sync data every 4 hours, So you need an application that runs periodically at specified times or intervals. As this first sounds easy, it is not as simple as you mean.You cannot simply use timers, timers will not continue to run within Suspend mode.

To have an application run at specific times, Windows Mobile supports a notification database. Your device will already wake up periodically to reschedule events and to clean up the notification database. Normally, Windows Mobile Phone devices will awake every night at 0:00.

There are also some other possible notifications that can launch an application, see my old web site.

How can we do a scheduled application ourself? At first run, the scheduler application has to delete all previous notification entries of the notification database. Then it has to create a new timed notification and in our sample, it will then launch another application. The scheduler application itself should be small and only care about the schedules. The worker application can be what you want and will be started by the scheduler application.

Continue reading ‘Howto run an application periodically’ »