/// <summary> /// Running Revit API code and get the result asynchronously /// </summary> /// <typeparam name="TResult">The type of the Result</typeparam> /// <param name="function">The delegate method wraps all the Revit API code with <see cref="UIApplication" /> as argument</param> /// <returns>The result</returns> public static Task <TResult> RunAsync <TResult>(Func <UIApplication, TResult> function) { var handler = new SyncDelegateExternalEventHandler <TResult>(); var futureExternalEvent = new FutureExternalEvent(handler); return(futureExternalEvent.RunAsync <Func <UIApplication, TResult>, TResult>(function)); }
/// <summary> /// Running Revit API code and get the result asynchronously /// </summary> /// <typeparam name="TResult">The type of the Result</typeparam> /// <param name="function">The delegate method wraps all the Revit API code with <see cref="UIApplication" /> as argument</param> /// <returns>The result</returns> public static Task <TResult> RunAsync <TResult>(Func <UIApplication, TResult> function) { var externalEventPair = SyncDelegateExternalEvents.GetOrAdd(typeof(TResult), _ => { var handler = new SyncDelegateExternalEventHandler <TResult>(); return(new ExternalEventPair(handler, () => CreateExternalEvent(handler))); }); return(externalEventPair.RunAsync <Func <UIApplication, TResult>, TResult>(function)); }