예제 #1
0
        public ProgressMonitor BeginAsyncStep(string message, int work)
        {
            if (currentTask == null)
            {
                throw new InvalidOperationException("Task not started in progress monitor");
            }
            if (work < 0)
            {
                throw new ArgumentException("work can't be negative");
            }

            ConsumePendingWork();
            if (message != null)
            {
                currentTask.Step(message, 0);
            }

            ProgressMonitor m = null;

            if (context != null)
            {
                context.Send((o) => m = CreateAsyncStepMonitor(), null);
            }
            else
            {
                m = CreateAsyncStepMonitor();
            }

            m.SetParentTask(this, currentTask, work);

            if (context != null)
            {
                context.Post((o) => {
                    OnBeginAsyncStep(message, work, m);
                    ReportProgressChanged();
                }, null);
            }
            else
            {
                OnBeginAsyncStep(message, work, m);
                ReportProgressChanged();
            }

            if (followerMonitors != null)
            {
                foreach (var sm in followerMonitors)
                {
                    m.AddFollowerMonitor(sm.BeginAsyncStep(message, work));
                }
            }
            return(m);
        }
예제 #2
0
        public ProgressMonitor BeginAsyncStep(string message, int work)
        {
            if (currentTask == null)
            {
                throw new InvalidOperationException("Task not started in progress monitor");
            }
            if (work < 0)
            {
                throw new ArgumentException("work can't be negative");
            }

            ConsumePendingWork();
            if (message != null)
            {
                currentTask.Step(message, 0);
            }

            ProgressMonitor m = null;

            if (context != null)
            {
                var state = new BeginAsyncStepState {
                    FromMonitor = this,
                };

                context.Send((o) => {
                    var bass           = (BeginAsyncStepState)o;
                    bass.ResultMonitor = bass.FromMonitor.CreateAsyncStepMonitor();
                }, state);

                m = state.ResultMonitor;
            }
            else
            {
                m = CreateAsyncStepMonitor();
            }

            m.SetParentTask(this, currentTask, work);

            if (context != null)
            {
                context.Post((o) => {
                    var(mon, msg, work1, stepMonitor) = (ValueTuple <ProgressMonitor, string, int, ProgressMonitor>)o;
                    MonitorBeginStepAsync(mon, msg, work1, stepMonitor);
                }, (this, message, work, m));
            }
            else
            {
                MonitorBeginStepAsync(this, message, work, m);
            }

            if (followerMonitors != null)
            {
                foreach (var sm in followerMonitors)
                {
                    m.AddFollowerMonitor(sm.BeginAsyncStep(message, work));
                }
            }
            return(m);

            void MonitorBeginStepAsync(ProgressMonitor mon, string msg, int work1, ProgressMonitor stepMonitor)
            {
                mon.OnBeginAsyncStep(msg, work1, stepMonitor);
                mon.ReportProgressChanged();
            }
        }