using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.Data;
          using System.Drawing;
          using System.Text;
          using System.Windows.Forms;
          using System.Threading;
          using System;
          using System.Threading;
          namespace DataImportFromAccess
          {

           

              //聲明一個(gè)回調(diào)函數(shù):注意傳遞的參數(shù)要與Example類中的函數(shù)參數(shù)類型一致
              public delegate void ExampleCallback(int lineCount, Label lb);
              public partial class Form1 : Form
              {
                  public Form1()
                  {
                      InitializeComponent();
                  }

                  public void CurrentNumber(int tempCurrent,Label lb)
                  {
                      lb.Text = tempCurrent.ToString();
                  }
                  private void button1_Click(object sender, EventArgs e)
                  {
                      ThreadWithData twd = new ThreadWithData(1, 100,this.label1,new ExampleCallback(CurrentNumber));
                      Thread td = new Thread(new ThreadStart(twd.RunMethod));
                      td.Start();
                  }   
                  private void button2_Click(object sender, EventArgs e)
                  {
                      ThreadWithData twd = new ThreadWithData(2, 200,this.label2, new ExampleCallback(CurrentNumber));
                      Thread td = new Thread(new ThreadStart(twd.RunMethod));
                      td.Start();
                  }
              }
              public class ThreadWithData
              {
                  private int start = 0;
                  private int end = 0;
                  private ExampleCallback callBack;
                  private Label lb;

                  public ThreadWithData(int start,int end,Label lb,ExampleCallback callBack)
                  {
                      this.start = start;
                      this.end = end;
                      this.callBack=callBack;
                      this.lb = lb;
                  }
                  public void RunMethod()
                  {
                      for(int i=start;i<end;i++)
                      {
                          Thread.Sleep(1000);
                          if (callBack != null)
                              callBack(i,lb);
                      }
                   
                  }
              }
          }

          posted on 2009-03-04 09:41 sanmao 閱讀(80) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 斗六市| 杂多县| 徐水县| 定安县| 乐陵市| 理塘县| 宁海县| 三亚市| 司法| 平远县| 龙陵县| 凉城县| 淮阳县| 延边| 孟村| 高平市| 包头市| 大石桥市| 丰都县| 天水市| 安溪县| 阿荣旗| 吴忠市| 蕉岭县| 册亨县| 兴业县| 永康市| 铜陵市| 墨脱县| 日照市| 沙湾县| 全椒县| 彰化市| 红安县| 青铜峡市| 慈利县| 巴青县| 沽源县| 威海市| 郯城县| 广昌县|