생성자: LongRunningTask(action, executingNode)

생성자: LongRunningTask(action, executingNode)

LongRunningTask
작업은 시간 제한 또는 CPU 제한 코드를 실행합니다.
LongRunningTask(Action action, IUANode executingNode);

인수

action
(Action)
실행할 메서드 또는 람다 식입니다.
executingNode
(IUANode)
코드가 실행되는 노드입니다.

예제

myLongRunningTask
작업은
ProcessCsvFile()
메서드를 사용하여 CSV 파일을 처리합니다. 이 메서드는 작업 자체를 인수로 사용하며, CSV 파일의 각 행을 읽은 후
IsCancellationRequested
속성을 사용하여 상태를 확인합니다. 이런 식으로 작업을 취소할 수 있습니다.
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; }
의견을 작성 부탁드립니다.
이 자료에 대한 문의사항이나 요청사항이 있습니까? 여기에 요청사항을 작성 부탁드립니다.
Normal