InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
idt_syncprimitives Namespace Reference

Detailed Description

An implementation of IIdleTask that uses cooperative threads to perform its task. You would use this if your idle task might take a long time to execute and you want to be able to yield back to the event loop without "losing your place", (i.e., you keep track of how far along your task is by using the stack and the program counter). You must override TaskName() and RunThread(). You do your work in RunThread(), periodically calling YieldToEventLoop(). At calls to YieldToEventLoop, if the IdleTaskMgr thinks you've had enough time because the user has generated an event or another IdleTask is ready to run, your RunThread() method will be suspended and scheduled to run again as soon as possible. At that time, the call to YieldToEventLoop() will unblock exactly where it left off. When you return from your RunThread() method, the thread will be destroyed and this IdleTask will be removed from the IdleTaskMgr's queue. Calling InstallTask() again will create a new thread and reinstall this IdleTask in the IdleTaskMgr's queue to be run as soon as possible.

Note that this class provides no facility for checking to see if the user wants to interrupt this task or if the task should end early for some other reason. You would have to do that by some other facility, perhaps by setting some state in response to a user event and checking that state the next time your thread wakes from the YieldToEventLoop() call. Simply returning anyplace from RunThread will then cause the thread to be destroyed and the IdleTask to be removed from the IdleTaskMgr.


include "CIdleTaskThread.h"
class MyIdleTask : public CIdleTaskThread
public:

MyIdleTask(IPMUnknown * boss) : CIdleTaskThread(boss){}

void RunThread();

const char* TaskName();
void MyIdleTask::RunThread()
uint32 flags;

work,work,work

flags = YieldToEventLoop(0);

work,work,work

flags = YieldToEventLoop(1000); //rest for 1 second

work,work,work

flags = YieldToEventLoop(0);

if( flags & kMouseTracking)

YieldToEventLoop(kOnFlagChange); //sleep til user stops tracking

work,work,work
if ( flags & kCITT_Shutdown )

    return;
const char* MyIdleTask::TaskName()
return "MyIdleTask";