Esempio n. 1
0
        private void OnWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker  worker     = sender as BackgroundWorker;
            TaskRunParameters parameters = e.Argument as TaskRunParameters;

            foreach (var item in parameters.Indices)
            {
                string fmt  = "D" + parameters.Parameter;
                string addr = string.Format(parameters.Expression, item.ToString(fmt));
                string locp = Program.GetLocalPath(addr, parameters.Destination);
                if (Program.Download(parameters.Client, addr, locp))
                {
                    ProgressMessage msg = new ProgressMessage(addr);
                    worker.ReportProgress(0, msg);
                }
                else
                {
                    addr = string.Format(parameters.Expression, item);
                    if (Program.Download(parameters.Client, addr, locp))
                    {
                        ProgressMessage msg = new ProgressMessage(addr);
                        worker.ReportProgress(0, msg);
                    }
                }
            }
        }
Esempio n. 2
0
        private void OnDispatcherDoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker     = sender as BackgroundWorker;
            TaskParameters   parameters = e.Argument as TaskParameters;

            parameters.DoneEvent = new AutoResetEvent(false);

            if (parameters.IsSingle)
            {
                string locp = Program.GetLocalPath(parameters.Source, parameters.Destination);
                if (Program.Download(parameters.Source, locp))
                {
                    worker.ReportProgress(100, new ProgressMessage(parameters.Source));
                }
            }
            else
            {
                workerList    = new List <BackgroundWorker>();
                parameterList = new List <TaskRunParameters>();

                for (int i = 0; i < parameters.ThreadCount; i++)
                {
                    BackgroundWorker wk = new BackgroundWorker();
                    wk.WorkerReportsProgress = true;
                    wk.ProgressChanged      += new ProgressChangedEventHandler(OnWorkerProgressChanged);
                    wk.RunWorkerCompleted   += new RunWorkerCompletedEventHandler(OnWorkerRunWorkerCompleted);
                    wk.DoWork += new DoWorkEventHandler(OnWorkerDoWork);
                    workerList.Add(wk);

                    TaskRunParameters tp = new TaskRunParameters();
                    tp.Destination = parameters.Destination;
                    tp.Expression  = parameters.Expression;
                    tp.Parameter   = parameters.Parameter;
                    parameterList.Add(tp);
                }

                int index = 0;
                for (int i = parameters.BeginIndex; i <= parameters.EndIndex; i++)
                {
                    if (index >= parameters.ThreadCount)
                    {
                        index = 0;
                    }
                    parameterList[index].Indices.Add(i);
                }

                for (int i = 0; i < parameters.ThreadCount; i++)
                {
                    workerList[i].RunWorkerAsync(parameterList[i]);
                }

                parameters.DoneEvent.WaitOne();
                Thread.Sleep(1000);
            }
        }
Esempio n. 3
0
        private void OnDispatcherDoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            TaskParameters parameters = e.Argument as TaskParameters;
            parameters.DoneEvent = new AutoResetEvent(false);

            if (parameters.IsSingle)
            {
                string locp = Program.GetLocalPath(parameters.Source, parameters.Destination);
                if (Program.Download(parameters.Source, locp))
                {
                    worker.ReportProgress(100, new ProgressMessage(parameters.Source));
                }
            }
            else
            {
                workerList = new List<BackgroundWorker>();
                parameterList = new List<TaskRunParameters>();

                for (int i = 0; i < parameters.ThreadCount; i++)
                {
                    BackgroundWorker wk = new BackgroundWorker();
                    wk.WorkerReportsProgress = true;
                    wk.ProgressChanged += new ProgressChangedEventHandler(OnWorkerProgressChanged);
                    wk.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnWorkerRunWorkerCompleted);
                    wk.DoWork += new DoWorkEventHandler(OnWorkerDoWork);
                    workerList.Add(wk);

                    TaskRunParameters tp = new TaskRunParameters();
                    tp.Destination = parameters.Destination;
                    tp.Expression = parameters.Expression;
                    tp.Parameter = parameters.Parameter;
                    parameterList.Add(tp);
                }

                int index = 0;
                for (int i = parameters.BeginIndex; i <= parameters.EndIndex; i++)
                {
                    if (index >= parameters.ThreadCount) index = 0;
                    parameterList[index].Indices.Add(i);
                }

                for (int i = 0; i < parameters.ThreadCount; i++)
                {
                    workerList[i].RunWorkerAsync(parameterList[i]);
                }

                parameters.DoneEvent.WaitOne();
                Thread.Sleep(1000);
            }
        }