Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:49:31+00:00 2026-05-26T14:49:31+00:00

What is the preferred way to check whether a scheduled task is active or

  • 0

What is the preferred way to check whether a scheduled task is active or not?

I’ll outline my solution below, but I am not sure this is indeed the best way to do it.


A scheduled task is created like this:

In[1]:= myTask=CreateScheduledTask[Print["task 1"], 30]

Out[1]= ScheduledTaskObject[1,Print[task 1],{30,Infinity},Automatic,False]

We can check for the existing tasks like this:

In[2]:= ScheduledTasks[]
Out[2]= {ScheduledTaskObject[1,Print[task 1],{30,Infinity},Automatic,False]}

The last entry in the ScheduledTaskObject (True or False) appears to indicate whether the task is started or not.

Now let’s start the task, and compare the contents of the variable myTask with the list returned by ScheduledTasks[].

In[3]:= StartScheduledTask[myTask]
Out[3]= ScheduledTaskObject[1,Print[task 1],{30,Infinity},Automatic,False]

In[4]:= {ScheduledTasks[],myTask}
Out[4]= {{ScheduledTaskObject[1,Print[task 1],{30,Infinity},Automatic,True]},
          ScheduledTaskObject[1,Print[task 1],{30,Infinity},Automatic,False]}

Note that they differ. The variable shows False while ScheduledTasks[] shows false. This demonstrates that the variable does not actually hold the task object. By modifying the variable myTask directly we can’t modify the task. The real state of the task is returned by ScheduledTasks[].

It looks reasonable to assume though that the first entry in the ScheduledTaskObject expression is a unique number corresponding to the task. So any manual operation performed on the task could perhaps use this number as a “handle”, and we could check the state of task with identifier 1 like this:

Cases[ScheduledTasks[], ScheduledTaskObject[1,__,state_] :> state]

I am not sure at all though that this approach (using the identifier from the ScheduledTaskObject) is correct. I have noticed situations when there were already some tasks in a fresh kernel (probably due to the front end — I had several notebook open, some with dynamic elements, and I’ve been experimenting with tasks), and sometimes ScheduledTasks[] returns several tasks with the same identifier (usually 0).

In summary:

  1. Is it a reliable way to handle tasks by their identifier (the first number from their ScheduledTaskObject)?

  2. What is the correct way to query the state of a scheduled task, given the expression we get from CreateScheduledTask when we first create it?

EDIT: If it’s possible, it would also be nice to have a Dynamic cell showing the state of a scheduled task, without using too much CPU. Does anyone have any ideas about how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:49:31+00:00Added an answer on May 26, 2026 at 2:49 pm

    The documentation for ScheduledTaskObject indeed uses id for the first argument and I think it is indeed unique. I have not been able to reproduce multiple ScheduledTaskObjects with the same id as you claim (nor ones with 0), so if you could provide a minimal example, it would be nice.

    In any case (assuming more than one task has the same id), you can narrow down your match by also checking for the exact definition of the task. Here’s a simple modification of yours.

     Clear@pollState
     pollState[task_ScheduledTaskObject] := 
     Module[{id = Level[task, 1][[1]], expr = Level[task, 1][[2]]},
      out = Cases[ScheduledTasks[], 
        ScheduledTaskObject[Evaluate@id, Evaluate@expr, __, state_] :> 
         state];
      Return[If[out === {}, "Task not found", First@out]]]
    

    You can create a Dynamic output of the state of your task and set the update interval to something like 1 second (or more), so that it doesn’t constantly poll for the state, hence slowing you down.

    Dynamic[Refresh[pollState[myTask], UpdateInterval -> 1]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which is the preferred way to check if a file exists and if not
If I need to check multiple conditions, which is the preferred way with respect
What is the preferred way to create a background task for a Rails application?
Is IAuthorizationFilter coupled with an attribute the preferred way to check if a user
is there a preferred way to check for existing documents via mongoid? if i
When writing a function I always have this confusion whether to check for errors
What is the preferred way to remove spaces from a string in C++? I
Is there a preferred way to handle animation when using Flex -- For instance,
What is the preferred way to open a URL from a thick client application
What would be your preferred way to concatenate strings from a sequence such that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.