コード例 #1
0
 public Job(AsyncWorkQueue queue, IWorkAsyncWrapper work)
 {
     this.queue                 = queue ?? throw new ArgumentNullException(nameof(queue));
     this.Work                  = work ?? throw new ArgumentNullException(nameof(work));
     this.postWorkCallBack      = work.PostWorkCallBack;
     this.Work.PostWorkCallBack = PostWorkCallBack;
 }
        public void WorkAsync(IWorkAsyncWrapper info)
        {
            Working += 1;
            var backgroundWorker = new BackgroundWorker();

            queueWorkers.Enqueue(backgroundWorker);

            if (info.Work == null && info.PostWorkCallBack == null)
            {
                throw new Exception("No Work to be done");
            }

            backgroundWorker.DoWork += new DoWorkEventHandler((sender, args) =>
            {
                info.Work?.Invoke(backgroundWorker, args);
            });

            backgroundWorker.ProgressChanged += new ProgressChangedEventHandler((sender, args) =>
            {
                info.ProgressChanged?.Invoke(args);
            });

            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender, args) =>
            {
                info.PostWorkCallBack?.Invoke(args);
                queueWorkers.Dequeue();
                Working -= 1;
            });

            backgroundWorker.RunWorkerAsync(info.AsyncArgument);
        }
コード例 #3
0
 public void WorkAsync(IWorkAsyncWrapper info)
 {
     BackgroundWorker = CreateBackgroundWorker();
     DoWorkEventArgs  = CreateWorkEventArgs(info.AsyncArgument);
     info.Work?.Invoke(BackgroundWorker, DoWorkEventArgs);
     RunWorkerCompletedEventArgs = CreateWorkCompletedEventArgs(DoWorkEventArgs);
     info.PostWorkCallBack?.Invoke(RunWorkerCompletedEventArgs);
 }
コード例 #4
0
        public void Enqueue(IWorkAsyncWrapper work)
        {
            var job = new Job(this, work);

            if (!queue.Any())
            {
                toolViewModel.AllowRequests = false;
                solutionPackagerControl.WorkAsync(job.Work);
            }
            queue.Enqueue(job);
        }
コード例 #5
0
        public void WorkAsync(IWorkAsyncWrapper info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }
            var workAsyncInfo = new WorkAsyncInfo();

            if (info.AsyncArgument != null)
            {
                workAsyncInfo.AsyncArgument = info.AsyncArgument;
            }
            if (info.Host != null)
            {
                workAsyncInfo.Host = info.Host;
            }
            if (info.IsCancelable)
            {
                workAsyncInfo.IsCancelable = info.IsCancelable;
            }
            if (info.Message != null)
            {
                workAsyncInfo.Message = info.Message;
            }
            if (info.MessageHeight > 0)
            {
                workAsyncInfo.MessageHeight = info.MessageHeight;
            }
            if (info.MessageWidth > 0)
            {
                workAsyncInfo.MessageWidth = info.MessageWidth;
            }
            if (info.PostWorkCallBack != null)
            {
                workAsyncInfo.PostWorkCallBack = info.PostWorkCallBack;
            }
            if (info.ProgressChanged != null)
            {
                workAsyncInfo.ProgressChanged = info.ProgressChanged;
            }
            if (info.Work != null)
            {
                workAsyncInfo.Work = info.Work;
            }
            WorkAsync(workAsyncInfo);
        }