示例#1
0
            private static void ThreadMainMethod()
            {
                // 0                1
                var waitHandles = new WaitHandle[] { NewMessageEvent, ShutdownEvent };
                var done        = false;

                while (done == false)
                {
                    // ReSharper disable once SwitchStatementMissingSomeCases
                    switch (WaitHandle.WaitAny(waitHandles))
                    {
                    case 0:     // NewMessageEvent
                    {
                        ProcessableQueue messagesToProcess;
                        var newQueue = new ProcessableQueue(QueueStartSize);

                        lock (QueueSyncObject)
                        {
                            messagesToProcess = _messageQueue;
                            _messageQueue     = newQueue;
                        }

                        SendMessagesToWriters(messagesToProcess);

                        messagesToProcess.ProcessingComplete = true;
                    }
                    break;

                    case 1:     // ShutdownEvent
                        done = true;
                        break;
                    }
                }
                ShutdownAckEvent.Set();
            }
示例#2
0
            static BackgroundThreadQueue()
            {
                lock (QueueSyncObject)
                {
                    _messageQueue = new ProcessableQueue(QueueStartSize);
                    LogWriters    = new List <ILogWriter>();

                    try
                    {
                        ConsumerThread = new Thread(ThreadMainMethod)
                        {
                            Name         = "BackgroundThreadQueue Worker",
                            IsBackground = false
                        };
                        ConsumerThread.Start();
                    }
                    catch (Exception e)
                    {
                        WriteSystem($"Unable to initialize BackgroundThreadQueue. Exception: {e}");
                    }
                }
            }