Beispiel #1
0
        private void SendMessage <TMessage>(TMessage message) where TMessage : class
        {
            lock (_lock)
            {
                if (_state == ApplicationState.Stopped)
                {
                    _log.ErrorFormat("Attempt to send message to stopped app: {0}", _host);
                    return;
                }

                if (_state == ApplicationState.Active)
                {
                    _messageBus.Notify(message);
                    return;
                }

                _messageQueue.Enqueue(MessageContainer.Create(message));

                if (_state == ApplicationState.Inactive)
                {
                    _state = ApplicationState.Activating;
                    ThreadPool.QueueUserWorkItem(s => Activate());
                }
            }
        }