コード例 #1
0
 /// <summary>
 /// 监听命令
 /// </summary>
 public void CommandListen()
 {
     using (AnonymousPipeClientStream pipe = new AnonymousPipeClientStream(PipeDirection.In, _commandPipeHandle))
     {
         byte[] commandByte = new byte[1024];
         while (true)
         {
             int    count   = pipe.Read(commandByte, 0, commandByte.Length);
             string command = Encoding.UTF8.GetString(commandByte, 0, count);
             if (command == "quit")
             {
                 _runner.Running = false;
             }
             try
             {
                 SendLog(new LogInfo {
                     TaskId = AppId, Level = LogLevel.Info, Message = "【执行命令】" + command
                 });
                 _runner.Command(command);
             }
             catch (Exception ex)
             {
                 SendLog(new LogInfo {
                     TaskId = AppId, Level = LogLevel.Error, Message = "【执行命令出错】" + ex.Message + ex.StackTrace
                 });
             }
         }
     }
 }