谁有双线程的例子 给个让学习下 谢谢

解决方案 »

  1.   

    http://topic.csdn.net/u/20080523/15/5f8057ff-7e59-4aa2-8d82-18a5fae5af39.html
    来自
      

  2.   


    using System;
    using System.Windows.Forms;namespace WindowsApplication39
    {
        public partial class Form1 : Form
        {        delegate void dShowForm();
            Form2 frm = new Form2();        public Form1()
            {
                this.InitializeComponent();
            }
            //显示窗体
            void ShowForm()
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new dShowForm(this.ShowForm));
                }
                else
                {
                    frm.ShowDialog(this);
                }
            }
            //控制进度
            void SetProgress()
            {
                for (int i = 1; i <= 100; i++)
                {
                    if (frm.DialogResult == DialogResult.Cancel)
                    {
                        //判断取消
                        break;
                    }
                    else
                    {
                        //模拟进度
                        frm.SetProgress(100, i);
                        System.Threading.Thread.Sleep(50);
                    }
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {
                new System.Threading.Thread(new System.Threading.ThreadStart(ShowForm)).Start();
                new System.Threading.Thread(new System.Threading.ThreadStart(SetProgress)).Start();
            }
        }
    }
    来自jinjazz