码迷,mamicode.com
首页 > 编程语言 > 详细

C#之参数线程

时间:2016-06-13 11:44:12      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

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)
        {
            
        }
    }

  

C#之参数线程

标签:

原文地址:http://www.cnblogs.com/mengluo/p/5579712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!