コード例 #1
0
ファイル: MessageDispatcher.cs プロジェクト: trydis/whitebox
        public void DispatchMessages(IReadQueue readQueue)
        {
            if (readQueue == null)
            {
                throw new ArgumentNullException("readQueue");
            }

            object message;

            while (readQueue.TryDequeue(out message))
            {
                var messageType    = message.GetType();
                var dispatchMethod = DispatchMessageOfTypeMethod.MakeGenericMethod(messageType);
                dispatchMethod.Invoke(this, new[] { message });
                _applicationEventDispatcher.DispatchApplicationEvents();
            }

            _applicationEventDispatcher.DispatchApplicationEvents();
        }
コード例 #2
0
        void WriteToQueue(object state)
        {
            try
            {
                if (!_clientStream.IsConnected)
                {
                    _clientStream.Connect((int)_connectionRetryInterval.TotalMilliseconds);
                }

                object message;
                while (_readQueue.TryDequeue(out message))
                {
                    var ms = new MemoryStream();
                    _formatter.Serialize(ms, message);
                    var bytes = ms.ToArray();
                    _clientStream.Write(bytes, 0, bytes.Length);
                    _clientStream.Flush();
                }

                ResetTimer();
            }
            catch (TimeoutException timeoutException)
            {
                Trace("Could not connect to profiler: {0}", timeoutException.Message);
                if (DateTime.Now - _initTime < _giveUpInterval)
                {
                    ResetTimer();
                }
                else
                {
                    Trace("Connection attempt threshold exceeded; detaching event queue and giving up.");
                    var nullQueue = new NullQueue();
                    _readQueue  = nullQueue;
                    _writeQueue = nullQueue;
                    Dispose();
                }
            }
            catch (Exception exception)
            {
                Trace("Error communicating with profiler, giving up: {0}", exception.Message);
            }
        }