Пример #1
0
        public void ExecuteCommand(Command command, CommandData data)
        {
            CommandItem comandWithData = new CommandItem(command, data);

            // find worker
            CoflnetThreadWorker worker = GetWorkerForUser(data.SenderId);

            // stack commandItem on the worker
            // it will be executed asyncronously
            worker.queuedCommand.Enqueue(comandWithData);

            internalCommandIndex++;

            // check every 100 commands that workers aren't overloaded
            if (internalCommandIndex % 100 != 0)
            {
                return;
            }
            //CheckWorkerBalance();
        }
Пример #2
0
        public void ExecuteNextCommand()
        {
            if (queuedCommand.Count > 0)
            {
                sleeping = false;
                CommandItem item = NextCommandItem();
                try
                {
                    CommandController.ExecuteCommandInCurrentThread(item.command, item.data);
                }
                catch (Exception ex)
                {
                    Track.instance.Error(item.data.Type, MessagePack.MessagePackSerializer.SerializeToJson(item), ex.ToString());
                }
            }
            else
            {
                if (isStopping)
                {
                    return;
                }
                if (!sleeping)
                {
                    long time = (DateTime.UtcNow - startTime).Ticks;
                }
                sleeping = true;
                ManualResetEvent resetEvent = new ManualResetEvent(false);
                resetEvent.WaitOne();


                resetEvent.Set();
                resetEvent.Reset();
                Thread.Sleep(100);
            }
            ExecuteNextCommand();
        }