Constructor: LongRunningTask(action, executingNode)
A
LongRunningTask
task runs time-bound or CPU-bound code.LongRunningTask(Action action, IUANode executingNode);
Arguments
- action(Action)
- The method or lambda expression to run.
- executingNode(IUANode)
- The node in which the code is ran.
Example
A
myLongRunningTask
task processes a CSV file using the ProcessCsvFile()
method. This method takes the task itself as argument, the status of which is checked using the IsCancellationRequested
property after reading each row of the CSV file. In this way, the task can be canceled.using namespace System.IO; // For using the StreamReader class public override void Start() { myLongRunningTask = new LongRunningTask(ProcessCSVFile, LogicObject); myLongRunningTask.Start(); } public override void Stop() { myLongRunningTask.Dispose(); } private void ProcessCsvFile(LongRunningTask task) { using (var reader = new StreamReader(pathToCsvFile)) { while (!reader.EndOfStream) { // Check whether task cancellation has been requested if (task.IsCancellationRequested) { // Properly handle task cancellation here return; } string line = reader.ReadLine(); // Process line } } } private LongRunningTask myLongRunningTask;
Provide Feedback