采用多线程方式,解决由于查询等待造成winfrom假死问题
1.这里是触发一个比较耗时的操作,比如一次大数据量的查询;
1 Thread thread = new Thread(new ThreadStart(DoWord)); 2 thread.Start();
2.开始处理数据
1 public delegate void InitItemInvoke(string str); 2 3 public void DoWord() 4 { 5 try 6 { 7 InitItemInvoke mi = new InitItemInvoke(InitQuotationItems); 8 string _strPostData = "{\"conditions\": [" + m_strFilter + "],\"paging\": {\"page\": 1,\"size\": 30}}"; 9 string result = BIMTService.CallPostService(PublicVar.BaseUrl + "/documents/search", _strPostData);//比较耗时的操作 10 BeginInvoke(mi, new object[] { result }); 11 } 12 catch (Exception ex) 13 { 14 LogHelper.WriteLog(typeof(ucLiteratureRecommend), "DoWord" + ex.Message); 15 } 16 }
3.数据返回,对UI界面进行更新
1 public void InitQuotationItems(string str) 2 { 3 //操作winform界面;5 }