Beispiel #1
0
        /// <summary>
        /// Enqueue and run an action against the game server.  Blocks until finished.
        /// </summary>
        /// <param name="act">the action to synchronously perform</param>
        public static void RunGatedAction(Action act, int queue = 0)
        {
            switch (queue)
            {
            case 0:
                GatedAction ba = new GatedAction()
                {
                    Action = act, CompletionToken = new ManualResetEvent(false)
                };
                Instance.GateQueue.Enqueue(ba);
                while (!ba.CompletionToken.WaitOne(500) && Instance.GateThreadsAlive)
                {
                }
                break;

            case 1:
                GatedAction ba2 = new GatedAction()
                {
                    Action = act, CompletionToken = new ManualResetEvent(false)
                };
                Instance.GateQueue2.Enqueue(ba2);
                while (!ba2.CompletionToken.WaitOne(500) && Instance.GateThreadsAlive)
                {
                }
                break;

            default:
                throw new Exception("unknown queue number");
            }
            if (!Instance.GateThreadsAlive)
            {
                throw new Exception("Gate was shut down.");
            }
        }
Beispiel #2
0
 private static void GateThreadLoop()
 {
     while (Instance.GateThreadsAlive)
     {
         Thread.Sleep(SlumberSpeed);
         GatedAction act = null;
         while (Instance.GateQueue.TryDequeue(out act) && Instance.GateThreadsAlive)
         {
             try
             {
                 act.Action();
             }
             catch (Exception ex) { log.Error("Gated action threw an error", ex); }
             finally
             {
                 act.CompletionToken.Set();
             }
             Thread.Sleep(ActionSpeed);
         }
     }
 }