Ejemplo n.º 1
0
        /// <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 and some other asynchronous processes with
        ///     <see cref="UIApplication" /> as argument
        /// </param>
        /// <returns></returns>
        public static Task <TResult> RunAsync <TResult>(Func <UIApplication, Task <TResult> > function)
        {
            var handler             = new AsyncDelegateExternalEventHandler <TResult>();
            var futureExternalEvent = new FutureExternalEvent(handler);

            return(futureExternalEvent.RunAsync <Func <UIApplication, Task <TResult> >, TResult>(function));
        }
Ejemplo n.º 2
0
        /// <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 and some other asynchronous processes with
        ///     <see cref="UIApplication" /> as argument
        /// </param>
        /// <returns></returns>
        public static Task <TResult> RunAsync <TResult>(Func <UIApplication, Task <TResult> > function)
        {
            var externalEventPair = AsyncDelegateExternalEvents.GetOrAdd(typeof(TResult), _ =>
            {
                var handler = new AsyncDelegateExternalEventHandler <TResult>();
                return(new ExternalEventPair(handler, () => CreateExternalEvent(handler)));
            });

            return(externalEventPair.RunAsync <Func <UIApplication, Task <TResult> >, TResult>(function));
        }