- プロジェクトの作成
- オブジェクトと変数のリファレンス
- プロジェクトの拡張
- チュートリアル
- グラフィックオブジェクト チュートリアル
コンストラクター: 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; }
ご質問やご意見