Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }