zoukankan      html  css  js  c++  java
  • Timer占用主线程

      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();
            }

  • 相关阅读:
    线上查询及帮助命令:
    windows: 2.7 3.5 (主要)
    get the execution time of a sql statement.
    java-kafka安装以及使用案例
    java-黑马头条 weex前端路由
    MYSQL安装
    缓存
    Flask中current_app和g对象
    [ValueError: signal only works in main thread]
    Flask-SQLAlchemy操作
  • 原文地址:https://www.cnblogs.com/liuxinls/p/2985215.html
Copyright © 2011-2022 走看看