As part of an automation script, we want to run a Task to run actions in parallel without blocking the code (allowing the Automation script to exit). We want to make use of Task.Factory.StartNew for this.
Is there any reason why this would not work?
Hi Michiel,
Normally you can use it. This is something that is also used during testing via automation scripts. However, it is highly recommended that the task itself is completed/cancelled before the script is completed (= done executing).
You can do this with the Wait function for example.
Some pseudo code:
using System; using System.Threading; using System.Threading.Tasks; using Skyline.DataMiner.Automation; namespace TestTaskScript { public class Script { public void Run(Engine engine) { string message = null; Task.Factory.StartNew(() => { message = $"If you see this, Then a task is generated."; }).ContinueWith(task => { message = $"{message} The task ID is {task.Id}."; }).Wait(); engine.GenerateInformation(message); } } }
Hope this helps you further
It is more safe to use when the script is running so that they are no hanging scripts or threads on your DataMiner if something would go wrong within the task.
Any reason why we need to ensure the task is completed prior to the script finishing?