From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

C# - Async wait for Execution.WaitForEndEx

I want to run a TestStand sequence via .NET API in C#. I'm currently doing as follows:

 

Engine tsEngine = new Engine();
SequenceFile testSequenceFile = tsEngine.GetSequenceFileEx(pathToMySequence);
SequenceFile processModelSequenceFile = tsEngine.GetSequenceFileEx("MyProcessModel", GetSeqFileOptions.GetSeqFile_FindFile, TypeConflictHandlerTypes.ConflictHandler_Error);
Execution tsExecution = tsEngine .NewExecution(testSequenceFile, "MainSequence", processModelSequenceFile, false, 0);

var result = tsExecution.WaitForEndEx(1000);

 

Everything works fine, and WaitForEndEx returns true.

 

How can I wait for execution end in an async way? If I run WaitForEndEx in a separate Task it always time outs (example next line).

 

Task.Run(() => tsExecution.WaitForEndEx(1000));

 

Thanks.

0 Kudos
Message 1 of 6
(1,924 Views)

Update: I tried to spawn tasks in several different ways, including a single task performing engine start sequence load and execution start, I also tried to execute the sequence via Dispatcher.CurrentDispatcher.Invoke thinking that it had to be run in the UI thread, but with no luck.

 

It seems that NewExecution and related WaitForEndEx can't be run in a separate Task.

 

Anyone could confirm or negate?

 

I'd really like to avoid to "import" in my GUI a complete TS UI just to silently run test sequences...

0 Kudos
Message 2 of 6
(1,891 Views)

Hi! Have you looked at this document at NI. It describes how to Execute a TestStand sequence asynchronously. As I understood your initial question was regarding that. 

Message 3 of 6
(1,728 Views)

Hi vardanium,

 

thanks for your answer, but how should it be related to my question? 

 

I'm speaking about "C# async await for Execution.WaitForEndEx", I posted C# code, and you're linking me a knowledge base about using TestStand editor...

 

I need to use TS Dotnet API.

 

Thank you and have a nice day.

0 Kudos
Message 4 of 6
(1,706 Views)

Hi Andrea,

 

Your request might solved, (at least I hope so) but I just hit on your topic and was wondering if you could give me a hint for a proper task synchronization.

 

Thanks in advance,

 

Br

Oliver

0 Kudos
Message 5 of 6
(1,599 Views)

Ciao Oliver,

 

unfortunately no, I've not been able to solve my issue. In the end I wrote my minimal test executive all in C#, and forgot about TestStand...

 

Good luck,

Andrea

0 Kudos
Message 6 of 6
(1,585 Views)