C#之参数线程

public Form1()
        {
            InitializeComponent();
        }
        Thread t;
        private void button1_Click(object sender, EventArgs e)
        {
            int num = int.Parse(this.textBox1.Text);
            int num2 = int.Parse(this.textBox2.Text);
            duo a = new duo();
            a.num1 = num;
            a.num2 = num2;
            t = new Thread(test);
           
            t.IsBackground = true;
            t.Start(a);

        }

        private void test(object num)
        {
            duo a = num as duo;
            
            
            //int n = 0;
            //while (n < 10000)
            //{

            //    n++;
            //    this.textBox1.Text = n.ToString();

            //}
            int n = a.num1;
            int b = a.num2;
            
            this.label1.Text = Convert.ToString((n + b) * b / 2);


            


        }

       

        private void Form1_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }
    }

  

数组



public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
        }
        Thread t;
        private void button1_Click(object sender, EventArgs e)
        {
            int num = int.Parse(this.textBox1.Text);
            int num2 = int.Parse(this.textBox2.Text);
            int[] a = new int[] { num,num2};
            t = new Thread(test);
           
            t.IsBackground = true;
            t.Start(a);

        }

        private void test(object num)
        {
            int[] nums=(int[])num;

            
            
            
            //int n = 0;
            //while (n < 10000)
            //{

            //    n++;
            //    this.textBox1.Text = n.ToString();

            //}
            int n = nums[0];
            int b = nums[1];
            
            this.label1.Text = Convert.ToString((n + b) * b / 2);


            


        }

       

        private void Form1_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }
    }

  

集合

public partial class Form1 : Form
    {
        List<int> add = new List<int>();
       
        public Form1()
        {
            InitializeComponent();
        }
        Thread t;
        private void button1_Click(object sender, EventArgs e)
        {
            add.Clear();
            int num = int.Parse(this.textBox1.Text);
            int num2 = int.Parse(this.textBox2.Text);
            add.Add(num);
            add.Add(num2);
            
            t = new Thread(test);
           
            t.IsBackground = true;
            t.Start(add);

        }

        private void test(object num)
        {
            //int nums=(int)num;
            List<int> nums = (List<int>)num;
            
            
            
            
            //int n = 0;
            //while (n < 10000)
            //{

            //    n++;
            //    this.textBox1.Text = n.ToString();

            //}
            int n = nums[0];
            int b = nums[1];
            
            this.label1.Text = Convert.ToString((n + b) * b / 2);


            


        }

       

        private void Form1_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }
    }

  

posted @ 2016-06-13 10:20  尘梦  阅读(156)  评论(0编辑  收藏  举报