Skip to main content
Known Participant
January 18, 2013
Question

[ID-CS5.5 plugin] The idle task is running while writing text in the document

  • January 18, 2013
  • 1 reply
  • 1078 views

Hi All,

I have written an idle task routine which periodically executing a simple function. Its working fine, except that it is trigerred even if the user is writing text in the document. What I want is that, the task should be halted when the user is writing. Here's my code-

uint32 MyIdleTask::RunTask( uint32 appFlags, IdleTimer* timeCheck)

{

          if (appFlags == IIdleTaskMgr::kMenuUp || appFlags == IIdleTaskMgr::kMouseTracking || appFlags == IIdleTaskMgr::kUserActive || appFlags == IIdleTaskMgr::kInBackground)

        return kOnFlagChange;

        do {

                     DothisTask();

             }while (false);

        return 5000;

}

Thanks in advance.

This topic has been closed for replies.

1 reply

Inspiring
January 18, 2013

You're checking for the case that one and only one flag can be set.

I don't believe that's the case. Try something like this.

if( appFlags & ( IIdleTaskMgr::kMouseTracking

    | IIdleTaskMgr::kUserActive

    | IIdleTaskMgr::kMenuUp

    | IIdleTaskMgr::kModalDialogUp ))

    {

        return  kOnFlagChange;

    }

Regards

Caerwyn

ShadowfaxAuthor
Known Participant
January 18, 2013

Thanks for the quick response.

I tried your code, but again, while writing the text the idle task is running. I confirmed that appFlags value was 0. What could be the reasons?

Inspiring
January 18, 2013

Reading the comment against kUserActive in the header file...

/** i.e., a real event caused this trip through the event loop as opposed to a sleep timeout */

which is possibly not the case...

If the function which you're exercising is causing hiccups in the user experience then you probably ought to be questioning if idle task is the right place for it, or if you're trying to do too much in an idle task.

You could try checking the IdleTimer parameter to see if you're cutting into too much idle time.

I'm not sure if there's a cross platform InDesign friendly way of doing this, but an alternative would be to write your own inactivity counter by installing a hook on thekeyboard.

On Windoze that would be something like

   theOldKeyboardHook = SetWindowsHookEx( WH_KEYBOARD, mykeyboardProcess, 0, myThreadId);

feels a bit kludgey, there might be some better suggestions from the more experienced ID programmers out there.