Esempio n. 1
0
    void Update()
    {
        UnityAction action;

        while (actions.TryDequeue(out action))
        {
            action();
        }
    }
Esempio n. 2
0
        private void StartWriteThread(object item)
        {
            MSMQContext context = item as MSMQContext;

            if (context == null)
            {
                return;
            }

            try
            {
                SafedQueue <SqlMessageQueue> msmqQueue = GetQueue(context.Index);
                while (true)
                {
                    try
                    {
                        while (msmqQueue.Count == 0)
                        {
                            Thread.Sleep(BufferWait);
                        }
                        List <SqlMessageQueue> smqBuffer = new List <SqlMessageQueue>(BufferMaxCount);
                        while (smqBuffer.Count < BufferMaxCount)
                        {
                            if (msmqQueue.Count == 0)
                            {
                                break;
                            }
                            SqlMessageQueue sqlMsgQueue;
                            if (msmqQueue.TryDequeue(out sqlMsgQueue))
                            {
                                smqBuffer.Add(sqlMsgQueue);
                            }
                            else
                            {
                                Thread.Sleep(SleepSeconds);
                            }
                        }
                        Interlocked.Exchange(ref writeCount, writeCount - smqBuffer.Count);
                        TraceWriteLine(string.Format("Queue [{0} _ {1}] has buffered {2} / {3}, remaining: {4}", context.MsgConfig.ManagerMessagePath, context.Index, smqBuffer.Count, BufferMaxCount, writeCount));

                        foreach (SqlMessageQueue itemQueue in smqBuffer)
                        {
                            if (itemQueue == null)
                            {
                                continue;
                            }
                            int runTimes = 0;
                            if (!DoSqlExecute(itemQueue, runTimes))
                            {
                                //失败重执行次数
                                ReDoSqlExecute(context, itemQueue, runTimes);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        LogHelper.WriteException(string.Format("Queue write {0} error:", context.MsgConfig.ManagerMessagePath), e);
                    }
                }
            }
            catch (Exception error)
            {
                LogHelper.WriteException(string.Format("Queue write {0} error:", context.MsgConfig.ManagerMessagePath), error);
            }
        }