Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

RScheduler and its Usage

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: manchb (31 Oct 2007)
Last edited: hamishwillee (26 Jul 2012)




RScheduler is a client-side interface to the Task Scheduler.


This class can be used for scheduling a task(s), which should be running at regular interval of time for example some Server Application.

We will be specifying the time for the task to be started and also the periodical check say Hourly,Daily,Monthly or yearly from the start time.If that task doesnt exist at that time mentioned, then Scheduler will start this task.

Example Codes

Header Files

1.#include <csch_cli.h> // RScheduler

2.#include <schinfo.h> // TScheduleEntryInfo, TSchedulerItemRef,TTaskInfo





The following are the steps followed to schedule a task:

1.Connect to the Task Scheduler.
2.Register to the Task Scheduler.
3.Create a time based Schedule i.e., information about the Start and End Time.
4.Schedule the Task i.e., Add this to the Schedule.
5.Disconnect to the Task Scheduler.

Connecting to the Task Scheduler

1.The following code snippet is used to Connect to the Task Scheduler:

RScheduler scheduler;

Register to the Task Scheduler

2.The following code snippet is used to Register to the Task Scheduler:

TFileName fileName;
fileName = _L("ExeName_to_be_Scheduled.exe");
User::LeaveIfError(scheduler.Register( fileName, CActive::EPriorityStandard ));

Create a time based Schedule i.e., information about the Start and End Time

3.The following code snippet is used to Create a time based Schedule:

First we set the Time when the Scheduler should start:

3.a.The following code snippet is used to retrieve the current time:

TTime lTime;
TTsTime startTime;
startTime.SetLocalTime( lTime );

3.b.The following code snippet is used to set Start Time for the Scheduler:

TScheduleEntryInfo2 lScheduleInfo2(startTime, EHourly, 1, KMaxTInt);

This will be scheduling the task every one hour with maximum validity period.

3.c.The following code snippet is used to Add the created ScheduledInfo into Scheduled entries:

CArrayFixFlat<TScheduleEntryInfo2>* array;
array = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
array->AppendL( lScheduleInfo2 );

TSchedulerItemRef class is used to uniquely identify the schedule.

TSchedulerItemRef itemRef;
User::LeaveIfError(scheduler.CreatePersistentSchedule( itemRef, *array ));

On execution of the above code, itemRef contains the Id(iHandle) for this Schedule using which we can refer this schedule in the future.

Schedule the Task i.e., Add this to the Schedule

4.The following code snippet is used to Schedule the Task:

TTaskInfo contains the information regarding the Task like its Id,Name,Priority,Repeater.

We pass the Schedule Id to the ScheduleTask().

TName taskName = _L("Test");
TTaskInfo taskInfo;
taskInfo.iTaskId = 0;
taskInfo.iName = taskName;
taskInfo.iPriority = CActive::EPriorityStandard;
taskInfo.iRepeat = -1;
HBufC* passData;
passData = KNullDesC().AllocL();
User::LeaveIfError(scheduler.ScheduleTask( taskInfo, *passData, itemRef.iHandle));

Disconnect to the Task Scheduler

5.The following code snippet is used to Disconnect from the Task Scheduler:


The following code snippet is used to query the information regarding a particular schedule :

TScheduleState2 lSchState;
CArrayFixFlat< TScheduleEntryInfo2 >* entryArray = new (ELeave)
CArrayFixFlat< TTaskInfo >* tskInfoArray = new (ELeave)
CArrayFixFlat< TTaskInfo >(1);
TTsTime dueTime;
//We pass the Id of the Schedule to this API using iHandle member of
//TSchedulerItemRef class
lSchState, *entryArray, *tskInfoArray, dueTime));
TBuf<20> lBuf;
lBuf = lSchState.Name();
CEikonEnv::Static()->InfoWinL(_L("Name "), lBuf);
if ( lSchState.Persists() != 0 )
CEikonEnv::Static()->InfoWinL(_L("Persists"), _L("True"));
CEikonEnv::Static()->InfoWinL(_L("Persists"), _L("False"));
if ( lSchState.Enabled() != 0 )
CEikonEnv::Static()->InfoWinL(_L("Enabled"), _L("True"));
CEikonEnv::Static()->InfoWinL(_L("Enabled"), _L("False"));
TTime schLocalTime = dueTime.GetLocalTime();

The following code snippet is used to query the information regarding a particular task associated with a schedule :

TTaskInfo taskInfoRet;
TSchedulerItemRef itemRefRet;
startTime taskDueTime;
TInt dataSize;
User::LeaveIfError(scheduler.GetTaskDataSize(taskInfo.iTaskId, dataSize );
HBufC* lDataBuf = HBufC::NewL(dataSize);
TPtr16 ptr=lDataBuf->Des();
//We pass the Id of the Task to this API using iTaskId member of TTaskInfo class
User::LeaveIfError(scheduler.GetTaskInfoL(taskInfo.iTaskId, taskInfoRet,
ptr, itemRefRet,taskDueTime ));
CEikonEnv::Static()->InfoWinL(_L("Task Name"), taskInfo.iName);
TBuf<5> repeatBuf;
CEikonEnv::Static()->InfoWinL(_L("Task repeat"), repeatBuf);
TTime taskLocalTime1 = taskDueTime.GetLocalTime();

The following code snippet is used to delete a specified task:


The following code snippet is used to delete a specified Schedule:

//Note that all the Tasks associated with this Scheduler must be deleted
// before executing this code.

Example Project



This page was last modified on 26 July 2012, at 05:40.
51 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.