/// <summary> /// A helper to asynchronus run a VI /// </summary> /// <param name="executionService">The execution services to use to run the VI</param> /// <returns>Task to await on. This will be completed when the VI finishes execution.</returns> public static Task RunAsync(this IExecutionService executionService) { TaskCompletionSource <bool> result = new TaskCompletionSource <bool>(); // Run the VI EventHandler <CurrentStateChangedEventArgs <ISimpleExecutionState> > viStateChangedEventHandler = null; viStateChangedEventHandler = ((s, a) => { if (a.NewExecutionState.IsIdle() && a.OldExecutionState.IsReserved()) { executionService.MasterExecutableFunction.CurrentSimpleExecutionStateChanged -= viStateChangedEventHandler; result.SetResult(true); } }); executionService.MasterExecutableFunction.CurrentSimpleExecutionStateChanged += viStateChangedEventHandler; executionService.StartRun(); return(result.Task); }