コード例 #1
0
 private void ThreadProc()
 {
     try
     {
         while (!_stopFlag)
         {
             try
             {
                 ConsoleCommand cmd = ConsoleCommandEvent.WaitAny(_recv);
                 if (cmd == ConsoleCommand.INVALID)
                 {
                     Trace.WriteLine("failed to receive command");
                 }
                 else
                 {
                     OnCommandReceived(cmd);
                 }
             }
             catch (Exception e)
             {
                 Trace.WriteLine(e);
             }
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e);
     }
 }
コード例 #2
0
        protected ConsoleBase(string magicCookie, bool create, ConsoleCommand[] send, ConsoleCommand[] recv)
        {
            if ((send == null || send.Length < 1) && (recv == null || recv.Length < 1))
            {
                throw new ArgumentNullException("send && recv");
            }

            try
            {
                _send = new ConsoleCommandEvent[send == null ? 0 : send.Length];
                for (int i = 0; i < _send.Length; ++i)
                {
                    _send[i] = new ConsoleCommandEvent(magicCookie, send[i], create);
                }

                _recv = new ConsoleCommandEvent[recv == null ? 0 : recv.Length];
                for (int i = 0; i < _recv.Length; ++i)
                {
                    _recv[i] = new ConsoleCommandEvent(magicCookie, recv[i], create);
                }
            }
            catch (WaitHandleCannotBeOpenedException ex)
            {
                EventLog.WriteEntry(Process.GetCurrentProcess().ProcessName, ex.ToString(), EventLogEntryType.Error);
                throw;
            }

            _thread              = new Thread(ThreadProc);
            _thread.Name         = "HA-IPC-Proc";
            _thread.IsBackground = true;
            _thread.Start();
        }
コード例 #3
0
ファイル: MasterConsole.cs プロジェクト: ilahsa/bai_pro
        public bool Start(int timeout)
        {
            if (_worker == null)
            {
                return(false);
            }

            if (!_workerInitialize.WaitOne(timeout))
            {
                return(false);
            }

            _status = WorkerStatus.Ready;
            if (!WriteCommand(ConsoleCommand.StartCommand))
            {
                return(false);
            }

            if (ConsoleCommandEvent.WaitAny(_startResponse, timeout) != ConsoleCommand.StartSuccess)
            {
                return(false);
            }

            _status = WorkerStatus.Running;
            return(true);
        }
コード例 #4
0
ファイル: MasterConsole.cs プロジェクト: ilahsa/bai_pro
        public MasterConsole(string magicCookie)
            : base(magicCookie, true,
                   new ConsoleCommand[] {
            ConsoleCommand.StartCommand,
            ConsoleCommand.PauseCommand,
            ConsoleCommand.ResumeCommand,
            ConsoleCommand.StopCommand,
            ConsoleCommand.PingCommand
        }, new ConsoleCommand[] {
            ConsoleCommand.PingResponse,
        }
                   )
        {
            _magicCookie = magicCookie;

            _startTime     = DateTime.Now;
            _lastHeartbeat = _startTime.AddSeconds(60.0);

            _startResponse = new ConsoleCommandEvent[2] {
                new ConsoleCommandEvent(magicCookie, ConsoleCommand.StartSuccess, true),
                new ConsoleCommandEvent(magicCookie, ConsoleCommand.StartFailure, true)
            };
            _workerInitialize = new ConsoleCommandEvent(magicCookie, ConsoleCommand.Initialized, true);
        }