Exemplo n.º 1
0
        private void progressChanged(object sender, ProgressChangedEventArgs e)
        {
            DownloadBW threadDownloading = sender as DownloadBW;

            if (threadDownloading == null || threadDownloading.program == null)
            {
                return;
            }

            threadDownloading.program.Progress = e.ProgressPercentage;
        }
Exemplo n.º 2
0
        private void completeWork(object sender, RunWorkerCompletedEventArgs e)
        {
            DownloadBW threadDownloading = sender as DownloadBW;

            if (threadDownloading == null)
            {
                return;
            }
            threadDownloading.program.ButtonText = "download";
            Console.WriteLine($"Completed: {threadDownloading.program.Position}");
            set.Remove(threadDownloading.program.ProgramName);
        }
Exemplo n.º 3
0
        private void StartThread(Model.Program program)
        {
            DownloadBW thread = new DownloadBW(program);

            thread.WorkerReportsProgress      = true;
            thread.WorkerSupportsCancellation = true;
            thread.DoWork             += new DoWorkEventHandler(doWork);
            thread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completeWork);
            thread.ProgressChanged    += new ProgressChangedEventHandler(progressChanged);

            thread.RunWorkerAsync(thread.program.ProgramName);
        }
Exemplo n.º 4
0
        private void doWork(object sender, DoWorkEventArgs e)
        {
            DownloadBW threadDownloading = sender as DownloadBW;

            if (threadDownloading == null)
            {
                return;
            }

            int count = threadDownloading.program.Progress;

            while (count < threadDownloading.program.TotalSize)
            {
                if (threadDownloading.program.Status == Model.Program.STOP)
                {
                    threadDownloading.program.Progress = 0;
                    threadDownloading.CancelAsync();
                    Console.WriteLine($"Canceled: '{threadDownloading.program.Position}' thread: '{count}'");
                    break;
                }
                else if (threadDownloading.program.Status == Model.Program.PAUSE)
                {
                    // write log
                    log.Info(new Model.DownHis()
                    {
                        DriverName = threadDownloading.program.ProgramName,
                        TotalSize  = (int)threadDownloading.program.TotalSize,
                        Progress   = threadDownloading.program.Progress,
                        Status     = threadDownloading.program.Status.ToString(),
                    });
                    //cancel thread
                    threadDownloading.CancelAsync();
                    break;
                }
                Console.WriteLine($"Processing: '{threadDownloading.program.Position}' thread: '{count}'");
                threadDownloading.ReportProgress(count);
                count++;
                Thread.Sleep(1);
            }
        }