基本信息
源码名称:C#多线程示例源码
源码大小:0.09M
文件格式:.rar
开发语言:C#
更新时间:2017-04-26
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

public MainWindow()
        {
            InitializeComponent();
        }
        //方式一
        DispatcherTimer tm = new DispatcherTimer();//实例化一个DispatcherTimer对象
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            tm.Tick  = new EventHandler(tm_Tick);//订阅Tick事件
            tm.Interval = TimeSpan.FromSeconds(0.05);
            tm.Start();
            // tm.Stop();
        }

        void tm_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value<=100)
            {
                progressBar1.Value  ;
                this.label2.Content = progressBar1.Value    "%";
            }
            else
            {
                tm.Stop();
            }
          
        }

        //方式二
        public void newActionThread(int value)
        {
            this.progressBar1.Value = value;
            this.label2.Content = progressBar1.Value     "%";
            System.Threading.Thread.Sleep(100);
        }
      
        // 使用线程 方法
        public void DispatcherThread()
        {
            Dispatcher newDispatcher = Dispatcher.CurrentDispatcher;//提供线程工作环境
            Action<int> newAction = new Action<int>(this.newActionThread);

            for (int i = 0; i < 100; i  )
            {
                newDispatcher.Invoke(newAction, i);
                System.Threading.Thread.Sleep(100);
                this.DoEvents();
                //   newDispatcher.Thread.Abort();
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            DispatcherThread();
        }