public string CallCmd(string eprocess, string method, string arg) { lock (syncObj) { string cmdtext = ""; bool IsCompleted = false;//是否完成 string retData = ""; actionReturnData = ((CmdObject cobj) => { if (cobj.uniqueid == CmdObject.AnalysisCmdText(cmdtext).uniqueid) { retData = cobj.retdata; IsCompleted = true; } }); cmdtext = CmdObject.BuildCmdText("efwplusserver", eprocess, Guid.NewGuid().ToString(), method, arg); if (eprocess == "efwplusbase") { ipcw_base.WriteData(cmdtext, IPCType.efwplusBase, IPCType.efwplusBase); } else if (eprocess == "efwpluswebapi") { ipcw_api.WriteData(cmdtext, IPCType.efwplusWebAPI, IPCType.efwplusWebAPI); } else if (eprocess == "efwplusroute") { ipcw_route.WriteData(cmdtext, IPCType.efwplusRoute, IPCType.efwplusRoute); } //超时计时器 Stopwatch sw = new Stopwatch(); sw.Start(); //是否超时 bool isouttime = false; while (!IsCompleted) { if (IsCompleted) { break; } //如果还未获取连接判断是否超时5秒,如果超时抛异常 if (sw.Elapsed >= new TimeSpan(5 * 1000 * 10000)) { isouttime = true; break; } else { Thread.Sleep(100); } } if (isouttime) { throw new Exception("命令执行超时"); } return(retData); } }
public string CallCmd(string eprocess, string method, string arg) { if (IPCName.GetProcessName(IPCType) == eprocess) { string cmdtext = CmdObject.BuildCmdText(IPCName.GetProcessName(IPCType), eprocess, Guid.NewGuid().ToString(), method, arg); string retval = funcExecCmd(CmdObject.AnalysisCmdText(cmdtext).methodstr, CmdObject.AnalysisCmdText(cmdtext).argdic);//执行命令 arg1方法名 arg2参数 //string datatext = CmdObject.BuildDataText(CmdObject.AnalysisCmdText(cmdtext).pathstr_end, CmdObject.AnalysisCmdText(cmdtext).pathstr_begin, CmdObject.AnalysisCmdText(cmdtext).uniqueid, retval); return(retval); } lock (syncObj) { string cmdtext = ""; bool IsCompleted = false;//是否完成 string retData = ""; actionReturnData = ((CmdObject cobj) => { if (cobj.uniqueid == CmdObject.AnalysisCmdText(cmdtext).uniqueid) { retData = cobj.retdata; IsCompleted = true; } }); if (IPCType == IPCType.efwplusBase) { cmdtext = CmdObject.BuildCmdText("efwplusbase", eprocess, Guid.NewGuid().ToString(), method, arg); ipcw.WriteData(cmdtext, IPCType.efwplusServer, IPCType); } else if (IPCType == IPCType.efwplusRoute) { cmdtext = CmdObject.BuildCmdText("efwplusroute", eprocess, Guid.NewGuid().ToString(), method, arg); ipcw.WriteData(cmdtext, IPCType.efwplusServer, IPCType); } else if (IPCType == IPCType.efwplusWebAPI) { cmdtext = CmdObject.BuildCmdText("efwpluswebapi", eprocess, Guid.NewGuid().ToString(), method, arg); ipcw.WriteData(cmdtext, IPCType.efwplusServer, IPCType); } //超时计时器 Stopwatch sw = new Stopwatch(); sw.Start(); //是否超时 bool isouttime = false; while (!IsCompleted) { if (IsCompleted) { break; } //如果还未获取连接判断是否超时5秒,如果超时抛异常 if (sw.Elapsed >= new TimeSpan(5 * 1000 * 10000)) { isouttime = true; break; } else { Thread.Sleep(100); } } if (isouttime) { throw new Exception("命令执行超时"); } return(retData); } }