# Scheduling and responding to repeated actions

**URL:** <https://mworks.discourse.group/t/scheduling-and-responding-to-repeated-actions/691>\
**Category:** Support\
**Created:** [February 22, 2011, 5:03pm UTC](https://mworks.discourse.group/t/scheduling-and-responding-to-repeated-actions/691 "2011-02-22T17:03:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 22, 2011, 5:03pm UTC](https://mworks.discourse.group/t/scheduling-and-responding-to-repeated-actions/691/1 "2011-02-22T17:03:23Z")

</div>

Hi Mark,

I’ve attached an example experiment (scheduled\_task.xml) that demonstrates MWorks’ “scheduled actions” feature. It’s roughly based on the scenario you described (i.e. scheduling a background thread that sends TTL pulses at regular intervals, and synchronizing to those pulses in your experiment).

The basic idea of the experiment is to set up a scheduled-actions component that sends a pulse (i.e. sets a variable to 1) 10 times, with a one-second delay between each pulse. Once the scheduled actions are started, the experiment uses a conditional state transition to wait for and record each pulse. Once all 10 pulses have been received, the experiment ends.

One limitation of this approach is that you have to know up front how many times you want the scheduled actions to run. An alternative approach would be to set the number of repetitions really large (so that the actions effectively repeat forever) and use a “cancel\_scheduled\_action” action to stop them. Unfortunately, there’s a [bug](http://mworks.lighthouseapp.com/projects/23610/tickets/71) that prevents this from working, so for the moment you’re stuck with using a fix number of repetitions.

In any case, scheduled actions should give you an alternative to spawning a background thread from your plugin code.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 22, 2011, 5:03pm UTC](https://mworks.discourse.group/t/scheduling-and-responding-to-repeated-actions/691/2 "2011-02-22T17:03:23Z")

</div>

Attachment: [scheduled\_task.xml](https://mworks.discourse.group/uploads/short-url/qB7HvE979F79n9q6uOKjI7Ucdzx.xml) (3.82 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 22, 2011, 8:32pm UTC](https://mworks.discourse.group/t/scheduling-and-responding-to-repeated-actions/691/3 "2011-02-22T20:32:05Z")

</div>

Thanks! I will try the plugin version first but I appreciate you constructing an example, it is likely to be useful in the future.  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 11:50pm UTC](https://mworks.discourse.group/t/scheduling-and-responding-to-repeated-actions/691/4 "2022-07-19T23:50:16Z")

</div>


