Constructor: PeriodicTask(action, periodMilliseconds, excutingNode)
A
PeriodicTask
task runs code at regular time intervals.PeriodicTask(Action action, int periodMilliseconds, IUANode executingNode);
Arguments
- action(Action)
- The method or lambda expression to run.
- periodMilliseconds(int)
- The time between the method or lambda expression runs.TIP:Consider the following example:
- TheperiodMillisecondsargument is set to 1000ms.
- The PeriodicTask executes a method that takes 500ms to complete.
- The PeriodicTask runs every 1500ms (periodMillisecondsvalue + method execution time).
- executingNode(IUANode)
- The node in which the code runs.
Example
The
myPeriodicTask
task runs the IncrementVariable()
method every second (1000 milliseconds). The method increments the value of the variable1
variable by one unit each time it runs.
public override void Start() { myPeriodicTask = new PeriodicTask(IncrementVariable, 1000, LogicObject); myPeriodicTask.Start(); } public override void Stop() { myPeriodicTask.Dispose(); } private void IncrementVariable() { variable1.Value = variable1.Value + 1; } private PeriodicTask myPeriodicTask;
TIP:
In this example, the
IncrementVariable()
method has no PeriodicTask
argument because the simplicity of its code does not require the task to be canceled.Provide Feedback