Ejemplo n.º 1
0
        /// <summary>
        /// Invokes an action in the GUI thread.
        /// </summary>
        public Task InvokeAsync(Action action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            var dispatcher = backendHost.Backend as IDispatcherBackend;

            if (dispatcher != null)
            {
                return(dispatcher.InvokeAsync(() => backendHost.ToolkitEngine.InvokeAndThrow(action)));
            }
            return(Application.InvokeAsync(() => backendHost.ToolkitEngine.InvokeAndThrow(action)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invokes a function in the GUI thread.
        /// </summary>
        public Task <T> InvokeAsync <T>(Func <T> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }
            Func <T> funcCall = () =>
            {
                T result = default(T);
                backendHost.ToolkitEngine.InvokeAndThrow(() => result = func());
                return(result);
            };
            var dispatcher = backendHost.Backend as IDispatcherBackend;

            if (dispatcher != null)
            {
                return(dispatcher.InvokeAsync(funcCall));
            }
            return(Application.InvokeAsync(funcCall));
        }