private void Excute(Stopwatch stopwatch = null) { try { var stopkey = Guid.NewGuid().ToString(); txt_stopkey.Text = stopkey; rtxt_Result.Text = string.Empty; var timeout = int.Parse(numeric_Timeout.Value.ToString()); string result = string.Empty; if (radio_local.Checked) { //socket result = SocketAccess.Access <string, string>( txtType.Text, rtxt_Param.Text, timeout, stopkey, Convert.ToInt32(txtAddress.Text)); } else { //http var url = txtAddress.Text + txtType.Text; var postData = rtxt_Param.Text.Replace("\n", ""); result = HttpHelper.Post(url, postData, null, timeout); } try { rtxt_Result.Text = CommonCla.ConvertJsonString(result); } catch { rtxt_Result.Text = result; } } catch (Exception ex) { try { rtxt_Result.Text = CommonCla.ConvertJsonString(ex.Message); } catch { rtxt_Result.Text = ex.Message; } } finally { if (stopwatch != null) { stopwatch.Stop(); } } }
private void rtxt_Param_Leave(object sender, EventArgs e) { try { if (rtxt_Param.Text.Contains("{")) { rtxt_Param.Text = CommonCla.ConvertJsonString(rtxt_Param.Text); } } catch { } }
string ProcessAndResult(string dataParam, ParamModel paramModel) { var resultModel = new ResultModel(); resultModel.IsSuccess = true; resultModel.Result = "666"; try { //设置并执行相应操作,核心方法 SetActionType(paramModel); try { //得到执行结果 while (!CommonCla.IsTimeout(paramModel.StartTime, paramModel.Timeout)) { resultModel.Result = _result; if (resultModel.Result == null) { if (MonitorStopProcess(paramModel.StopKey)) { resultModel.Result = ArtificialCode.A_RequestNormalBreak.ToString(); break; } if (IsDisposed) { throw new Exception(ArtificialCode.A_RequestAccidentBreak.ToString()); } Thread.Sleep(100); } else { resultModel.IsSuccess = true; break; } } if (resultModel.Result == null) { throw new Exception(ArtificialCode.A_TimeOutResult.ToString()); } } catch (Exception ex)//获取结果发生错误 { resultModel.Result = ex.Message; //_log.ErrorFormat("耗时:{0}\r\n{1}\r\n{2}", CommonCla.GetMilliseconds(paramModel.StartTime), dataParam, resultModel.Result); } } catch (Exception ex)//解析参数发生错误 { //如果Start发生异常 _isWorking = false; resultModel.Result = ex.Message; //_log.FatalFormat("{0}\r\nStart()\r\n{1}", paramModel.Method, ex.Message); } finally { Task.Run(() => { //本次执行完成,退出使用 //不阻塞执行,尽快返回结果 try { //TODO这个地方有空引用,正常这是不可能的,暂时不处理 _process?.End(); _process = null; } catch (Exception ee) { //var position = nameof(ProcessForm) + "--" + nameof(Quit); System.Diagnostics.Process.GetCurrentProcess().Kill(); } }); } return(JsonConvert.SerializeObject(resultModel)); }
string ProcessAndResult(FormBrowser form, string dataParam, ParamModel paramModel) { var resultModel = new ResultModel(); resultModel.IsSuccess = true; resultModel.Result = "666"; try { //设置并执行相应操作,核心方法 form.SetActionType(paramModel); try { //得到执行结果 while (!CommonCla.IsTimeout(paramModel.StartTime, paramModel.Timeout)) { resultModel.Result = form._result; if (resultModel.Result == null) { if (MonitorStopProcess(paramModel.StopKey)) { resultModel.Result = ArtificialCode.A_RequestNormalBreak.ToString(); break; } if (form.IsDisposed) { throw new Exception(ArtificialCode.A_RequestAccidentBreak.ToString()); } Thread.Sleep(100); } else { resultModel.IsSuccess = true; break; } } if (resultModel.Result == null) { throw new Exception(ArtificialCode.A_TimeOutResult.ToString()); } } catch (Exception ex)//获取结果发生错误 { resultModel.Result = ex.Message; //_log.ErrorFormat("耗时:{0}\r\n{1}\r\n{2}", CommonCla.GetMilliseconds(paramModel.StartTime), dataParam, resultModel.Result); } } catch (Exception ex)//解析参数发生错误 { //如果Start发生异常 form._isWorking = false; resultModel.Result = ex.Message; //_log.FatalFormat("{0}\r\nStart()\r\n{1}", paramModel.Method, ex.Message); } finally { Task.Run(() => { //本次执行完成,退出使用 //不阻塞执行,尽快返回结果 form.ProcessEnd(); }); } return(JsonConvert.SerializeObject(resultModel)); }