コード例 #1
0
ファイル: Node.cs プロジェクト: CrazyPokemonDev/WhoAmIBot
 private void Queue_Thread()
 {
     try
     {
         using (var sw = new StreamWriter(Pipe))
         {
             Console.WriteLine("Queue thread at {0} started", Path);
             while (true)
             {
                 try { Pipe.WaitForConnection(); } catch (InvalidOperationException) { }
                 if (queue.Count < 1)
                 {
                     queueReset.Reset();
                 }
                 queueReset.WaitOne();
                 var data = queue[0];
                 sw.WriteLine(data);
                 sw.Flush();
                 Pipe.WaitForPipeDrain();
                 queue.Remove(data);
             }
         }
     }
     catch
     {
         Console.WriteLine("Queue thread of node at {0} stopped.", Path);
         State = NodeState.Stopped;
         NodeStopped?.Invoke(this, this);
     }
 }
コード例 #2
0
ファイル: Node.cs プロジェクト: CrazyPokemonDev/WhoAmIBot
 public void Stop()
 {
     QThread.Abort();
     try
     {
         Process.Kill();
     }
     catch (Exception x)
     {
         Console.WriteLine("Node at {1}:\nFailed to kill process with error: {0}", x.Message, Path);
     }
     State = NodeState.Stopped;
     NodeStopped?.Invoke(this, this);
 }