NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Test Stand async Task<bool>

I'm trying to learn more about NI Test Stand and calling a .NET Method in a test sequence.  I reviewed and understand the basic examples where you can call something like below...

 

public bool DoSomething(out string result, out string error) { //...}

 

I have a third-party libary and it includes some async Methods that must be called using the async/await feature that was introduced in .NET 4.5.  When using async, you can not use the out keyword in arguments, so I would have to modify the Method above to something like this...

 

public Task<Tuple<bool, string, string>> DoSomething() { /.. }

 

So my question is... does anyone know how to call into a .NET library with Test Stand and get the values that are returned via the async Task?  Any basic examples are appreciated.

 

BTW, it does not have to be complex like above.  If you can explain something like Task<bool>, it would help, as well.

 

Thanks.

0 Kudos
Message 1 of 3
(3,283 Views)

I haven't tried this specific case and am not familiar with the Task API, but you should be able to store the return value of that method in a TestStand Object Reference variable. Then, in a later step, select the class Task<Tuple<bool, string, string>> from your assembly and use the reference you got from the previous call as the class object and then just access the various methods and properties of that class.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 3
(3,259 Views)

An old question, I can see, but google led me here - so I thought I would give my input:

If you make this call:

DoSomething().GetAwaiter().GetResult()

it will wait for the call to end - and you will get the result (fx Tuple<bool, string, string> as suggested).

 

You can also call DoSomething() and store the Task-object-reference in a variable, fx Locals.DoSomethingTask, as dug9000 suggests,

and go on to do something else meanwhile. Later you can call GetAwaiter.GetResult() on the Locals.DoSomethingTask object - and it will wait if the task is not finished, or it will return immediately if it is. In any case, at this time you will get the result from the DoSomething() call.

 

Example.png

Message 3 of 3
(1,765 Views)