werqxz
werqxz
2016-04-20 09:32

c#,winform,为防止界面卡死,新建线程运行耗时算法,速度骤降

  • winform
  • c#
  • 线程

原本单线程下3分钟,创建个线程这么做之后要35分钟,各位大哥大姐行行好,告诉我这个怎么破?

 //齐套分析按钮事件
        private void btnQtfx_Click(object sender, EventArgs e)
        {
            qtfxStart();            //启动进度条
            if (gridView1.RowCount > 0)
            {
                int[] selected = this.gridView1.GetSelectedRows();          //得到选中行
                calculateThread = new Thread(new ParameterizedThreadStart(qtfx));
                //calculateThread.Priority = ThreadPriority.Highest;
                calculateThread.Name = "分析线程";
                calculateThread.Start(selected);                //把选中行索引传到qtfx方法
            }
            else
            {
                MessageBox.Show("没有数据");
            }
        }
        //齐套分析
        private void qtfx(Object o)
        {

            int[] selected = (int[])o;          //得到传进来的参数
            AnalysisManage am = new AnalysisManage(dt_storey, dt_onway);
            DateTime begin = DateTime.Now;      
            DataTable dt = am.analysis(selected);                         //齐套分析,问题在这一句,最耗时
            CallbackWithDT qt = new CallbackWithDT(qtfxDone);
            this.Invoke(qt, new object[] { dt });                           //把分析结果传到“窗体线程”
            DateTime end = DateTime.Now;
            MessageBox.Show((end - begin).ToString());
        }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答