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 runs.

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 System.IO; // For using the StreamReader

public class RuntimeNetLogic1 : BaseNetLogic
{
    public override void Start()
    {
        // Insert code to be executed when the user-defined logic is started
        myLongRunningTask = new LongRunningTask(ProcessCsvFile, LogicObject);
        myLongRunningTask.Start();
    }

    public override void Stop()
    {
        // Insert code to be executed when the user-defined logic is stopped
        myLongRunningTask.Dispose();
    }
    
    private void ProcessCsvFile(LongRunningTask task)
{
    // example method to read lines from a csv file
    using (var reader = new StreamReader("path/to/csv/file.csv"))
    {
        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;
}