private void showError(String msg, MonitorModel model) { toLog(msg); try { Uri uri = new Uri(ConfigModel.getMsgHost() + model.host + msg); WebClient webClient = new WebClient(); byte[] byt = webClient.DownloadData(uri); String content = System.Text.Encoding.UTF8.GetString(byt); LogHelper.Log("发送消息"); } catch (Exception ex) { LogHelper.Log("消息发送异常:" + ex); } /* * msgForm = new MsgForm(model.host + "异常", msg); * msgForm.ShowDialog();//正常 */ showErrorThread = new Thread(new ParameterizedThreadStart(showMsgForm)); MsgModel msgModel = new MsgModel(); msgModel.Name = model.host + "异常"; msgModel.Remark = msg; showErrorThread.Start(msgModel); }
private void showMsgForm(Object obj) { //toLog("发现异常,请及时处理,休眠:"+ ConfigModel.getWarnTime()); new Thread(new ThreadStart(() => { //休眠多少x秒后,关掉显示错误消息的线程,让线程继续走 Thread.Sleep(ConfigModel.getWarnTime()); msgForm.Close(); showErrorThread.Abort();//结束线程,让它重新开始执行 })).Start(); MsgModel msgModel = (MsgModel)obj; msgForm = new MsgForm(msgModel.Name, msgModel.Remark); msgForm.ShowDialog(); if (showErrorThread != null && showErrorThread.IsAlive) { showErrorThread.Abort();//结束线程,让它重新开始执行 } }