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

//timer 开辟新线程,不占用主线程

时间:2016-03-01 16:00:20      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

  private void timer1_Tick_1(object sender, EventArgs e)
        {

           //开辟新线程,不占用主线程
            Thread t = new Thread(new ThreadStart(delegate
            {
                timer1.Stop();
                while (true)
                {
                    Console.WriteLine("in timer1_Tick_1");
                    if (result.Count >= number)
                    {
                        Console.WriteLine("result.Count = " + result.Count);
                        Console.WriteLine("start saving");
                        for (int i = 0; i < result.Count; i++)
                        {
                            dt.AirwayTables.InsertOnSubmit(result[i]);
                            //Console.WriteLine(result[i].TimeTick + " has benn saved!");
                        }
                        dt.SubmitChanges();
                        Console.WriteLine("Saved");
                        result = new List<AirwayTable>();
                    }
                    Application.DoEvents();
                    Console.WriteLine("out timer1_Tick_1");
                    Thread.Sleep(1000);
                }
            }));
            t.Start();
        }

 

http://www.cnblogs.com/liuxinls/archive/2013/03/27/2985215.html

//timer 开辟新线程,不占用主线程

标签:

原文地址:http://www.cnblogs.com/boke813009577/p/5231310.html

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