Message Boards Message Boards

1
|
3477 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

Trouble With RunScheduledTask

Posted 10 years ago

I seem to be having trouble with RunScheduledTask[]. Here is my code...

tasks = {"Task A", "Task B", "Task C", "Task D"};
tooEarly = TimeObject[{8, 0, 0}];
tooLate = TimeObject[{21, 0, 0}];
taskPicker[tooEarly_, tooLate_] := Module[{task, now},
  now = TimeObject[];
  If[tooEarly < now && now < tooLate,
   task = RandomChoice[tasks];
   MessageDialog[StringJoin["Time to do task: ", task, " "]];

   ]
  ]
RunScheduledTask[taskPicker[tooEarly, tooLate], 5];

If I run that, my MessageBox pops up as expected, 5 seconds after I hit Shift-Return.

But the, 5 seconds later, I get the following in the Messages window...

enter image description here

...and I never see my dialog again.

It I take out the lines in my taskPicker function that involve querying for the current time, it all works...

taskPicker[tooEarly_, tooLate_] := Module[{task, now},

  task = RandomChoice[tasks];
  MessageDialog[StringJoin["Time to do task: ", task, " "]];

  ]

It is as though you cannot run TimeObject[] within a scheduled task.

POSTED BY: Brad Varey
Posted 10 years ago

You have to use:

now = TimeObject[Now];

why? I don't know, Ask WRI. :)

POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract