示例#1
0
        /// <summary>
        /// Runs an asynchronious operation using a STA thread
        /// </summary>
        /// <param name="workerParams"></param>
        /// <param name="work"></param>
        /// <param name="completeHandler"></param>
        public static void RunSTA(ProgressWorkerParams workerParams, Action <IProgressVisualizer> work, Action completeHandler)
        {
            if (work == null)
            {
                throw new ArgumentNullException("work");
            }

            IProgressVisualizer progressVisualizer = null;

            AsyncHelper.RunAsyncSTA(
                operation =>
            {
                progressVisualizer = (new DefaultProgressService()).CreateVisualizer(workerParams);

                work(progressVisualizer);
            },
                () =>
            {
                progressVisualizer.Complete();
                if (completeHandler != null)
                {
                    completeHandler();
                }
            });
            Application.DoEvents();
        }
        public static void Run(
            [NotNull] IServiceProvider provider,
            bool allowCancel,
            [NotNull] Action <IProgressVisualizer> work,
            [CanBeNull] Action completeHandler)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (work == null)
            {
                throw new ArgumentNullException("work");
            }

            IProgressVisualizer progressVisualizer = null;

            AsyncHelper.RunAsync(
                asyncOp =>
            {
                progressVisualizer = provider
                                     .GetRequiredService <IProgressService>()
                                     .CreateVisualizer(allowCancel);

                work(progressVisualizer);
            },
                () =>
            {
                progressVisualizer.Complete();
                if (completeHandler != null)
                {
                    completeHandler();
                }
            });

            Application.DoEvents();
        }