zoukankan      html  css  js  c++  java
  • delegate Thread 的简单使用

    using System;
    using System.Windows.Forms;
    using System.Threading;

    namespace _Delegate
    {
      
        delegate void GetDelegate();
        delegate void DelegateStart();
        delegate void TimeSprogressStep(int index);
        delegate void DelegateFinished(string Message);
        public partial class Form1 : Form
        {
            Thread aThread;
            DelegateStart delegatestart;
            TimeSprogressStep timesprogressstep;
            DelegateFinished delegatefinished;
            static int icount = 0;
            int sum = 0;

            public Form1()
            {
                InitializeComponent();

                delegatestart = new DelegateStart(this.Start);
                timesprogressstep = new TimeSprogressStep(this.TimeSprogresStep);
                delegatefinished = new DelegateFinished(this.DelegateFinished);
            }
          
            private void btnThread(object sender, EventArgs e)
            {
                aThread = new Thread(new ThreadStart(this.thread_Ms));
                aThread.IsBackground = true;
                aThread.Start();          
            }

            private void Start()
            {
                this.lblcontent.Text = "";
                sum = 1000;
                this.timeprogressBar.Maximum = sum;
                this.button2.Enabled = false;
            }
            private void TimeSprogresStep(int index)
            {
                this.timeprogressBar.PerformStep();           
                this.lblcontent.Text = string.Format("Status:{0}",index);
            }

            private void DelegateFinished(string mess)
            {          
                this.button2.Enabled = true;
                this.timeprogressBar.Value = 0;
            }
            protected void thread_Ms()
            {
                icount = 0;
                this.Invoke(delegatestart);
                     
                while (icount < sum)
                {                               
                    timeprogressBar.Invoke(this.timesprogressstep, new object[] { icount});
                    Application.DoEvents();                
                    icount++;
                }

                this.Invoke(this.delegatefinished, new object[] { "全部完成!"});
            }

            private void btnDelegate(object sender, EventArgs e)
            {
                GetDelegate mDelegate = new GetDelegate(this.thread_Ms);
                mDelegate();
            }
        }
    }

  • 相关阅读:
    Ubuntu12.04安装svn1.8
    [NOIP模拟测试3] 建造游乐园 题解(欧拉图性质)
    图论模板
    [bzoj3073] Journeys 题解(线段树优化建图)
    [bzoj3033]太鼓达人 题解(搜索)
    [NOIP2016]天天爱跑步 题解(树上差分) (码长短跑的快)
    [HNOI2015]菜肴制作 题解(贪心+拓扑)
    [SDOI2015]排序 题解 (搜索)
    [CQOI2011]放棋子 题解(dp+组合数学)
    [ZJOI2011]看电影(组合数学/打表+高精)
  • 原文地址:https://www.cnblogs.com/snlfq2000/p/1375732.html
Copyright © 2011-2022 走看看