日期:2014-05-17  浏览次数:20740 次

新手初学线程问题?
        private DateTime starttime = new DateTime();
        private void button5_Click(object sender, EventArgs e)
        {

            starttime=DateTime.Now;

            Thread thread = new Thread(new ThreadStart(Dosomething));

            thread.IsBackground = true;

            thread.Start();
        }

        private void Dosomething( )
        {
            
            while(true)
            {

                DateTime now = DateTime.Now;
                Thread.Sleep(100);

                if (now.Second > starttime.Second+10)
                {
                    //其它处理

                    break;
                }
            }
        }


问题1  break实行后这个线程是否还在运行?
问题2 Dosomething可不可以有参数?如Dosomething(int para)等等.

------解决方案--------------------
1、break跳出循环。如果事情干完了,就结束。
2、可以带参数。http://blog.csdn.net/wangzh300/article/details/6969354
------解决方案--------------------

  new Thread(new ThreadStart(() =>
        {
            Dosomething("aa");
        })).Start();

 private void Dosomething(string aa)
     &n