생성자: LongRunningTask(action, executingNode)

LongRunningTask
작업은 시간 제한 또는 CPU 제한 코드를 실행합니다.
LongRunningTask(Action action, IUANode executingNode);
팁: 긴 작업이나 차단 작업에는
LongRunningTask
를 사용하십시오. 특히 코드가 프로젝트 노드에 액세스해야 하는 경우에 그렇습니다. 수명 주기 메서드는 짧게 유지하고, 가능하면 확장된 작업은
Start()
밖으로 이동하십시오. 스레딩에 대한 자세한 내용은 런타임 스레딩 모델을 참조하십시오.

인수

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