Exemple #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            DownLoadFile fd1 = new DownLoadFile();

            fd1.FileName = "myfile.txt";
            DownLoadFile fd2 = new DownLoadFile();

            fd2.FileName = "myfile2.txt";
            DownLoadFile fd3 = new DownLoadFile();

            fd3.FileName = "myfile3.txt";

            DownLoadFile fd4 = new DownLoadFile();

            fd4.FileName = "myfile4.txt";
            DownLoadFile fd5 = new DownLoadFile();

            fd5.FileName = "myfile5.txt";


            List <DownLoadFile> Quefd = new List <DownLoadFile>();

            Quefd.Add(fd1);
            //Quefd.Add(fd2);
            //Quefd.Add(fd3);
            //Quefd.Add(fd4);
            //Quefd.Add(fd5);
            QueueThreadBase thfd = new QueueThreadBase(Quefd);

            thfd.OneJobStart  += ShowOneStartMsg;
            thfd.OneCompleted += ShowOneDoneMsg;
            thfd.AllCompleted += ShowAllDoneMsg;
            thfd.Start();
        }
Exemple #2
0
 public void ShowOneDoneMsg(DownLoadFile x, CompetedEventArgs args)
 {
     if (this.tb5.InvokeRequired)
     {
         InvokeMsg1 msgCallback = new InvokeMsg1(ShowOneDoneMsg);
         tb5.Invoke(msgCallback, new object[] { x, args });
     }
     else
     {
         tb5.Text += x.FileName + " finished!" + "  完成率:" + Convert.ToString(args.CompetedPrecent) + "%  " + Environment.NewLine;
     }
 }
Exemple #3
0
 public void ShowOneStartMsg(DownLoadFile x)
 {
     if (this.tb5.InvokeRequired)
     {
         InvokeMsg0 msgCallback = new InvokeMsg0(ShowOneStartMsg);
         tb5.Invoke(msgCallback, new object[] { x });
     }
     else
     {
         tb5.Text += x.FileName + " begin!" + Environment.NewLine;
     }
 }
Exemple #4
0
 private void OnOneJobStart(DownLoadFile pendingValue)
 {
     if (OneJobStart != null)
     {
         try
         {
             //MessageBox.Show("所有任务完成!");
             OneJobStart(pendingValue);//--一个任务开始了..
         }
         catch { }
     }
 }
Exemple #5
0
 /// 引发单个完成事件
 private void OnOneCompleted(DownLoadFile pendingValue, CompetedEventArgs args)
 {
     if (OneCompleted != null)
     {
         try
         {
             //MessageBox.Show("单个任务完成!");
             OneCompleted(pendingValue, args);
         }
         catch { }
     }
 }
Exemple #6
0
 protected DoWorkResult DoWork(DownLoadFile pendingValue)
 {
     try
     {
         string jna = pendingValue.FileName;
         //MessageBox.Show("正在执行任务" + jna);
         //--- 这里如何通知主界面,任务正在执行...
         //for(int i = 0; i < 5; i++)
         //{
         //    Console.WriteLine("任务名:{0} 正在执行第{1}次", jna, i);
         //}
         //..........多线程处理....
         return(DoWorkResult.ContinueThread);//没有异常让线程继续跑..
     }
     catch (Exception)
     {
         return(DoWorkResult.AbortCurrentThread); //有异常,可以终止当前线程.当然.也可以继续,
                                                  //return  DoWorkResult.AbortAllThread; //特殊情况下 ,有异常终止所有的线程...
     }
 }