Esempio n. 1
0
        public RequestHandler(PipeStreamWrapper pipeStreamWrapper, Func <T> handlerFactoryFunc)
        {
            _pipeStreamWrapper  = pipeStreamWrapper;
            _handlerFactoryFunc = handlerFactoryFunc;

            _pipeStreamWrapper.RequestHandler = this;
        }
Esempio n. 2
0
        public async void StartProcessing(PipeStreamWrapper pipeStreamWrapper)
        {
            if (State != PipeState.NotOpened)
            {
                throw new InvalidOperationException("Can only call connect once");
            }

            State = PipeState.Connected;

            try
            {
                _workLoopCancellationTokenSource = new CancellationTokenSource();

                // Process messages until canceled.
                while (true)
                {
                    _workLoopCancellationTokenSource.Token.ThrowIfCancellationRequested();
                    await pipeStreamWrapper.ProcessMessageAsync(_workLoopCancellationTokenSource.Token);
                }
            }
            catch (OperationCanceledException)
            {
                // This is a normal dispose.
                State = PipeState.Closed;
            }
            catch (Exception exception)
            {
                State     = PipeState.Faulted;
                PipeFault = exception;
            }
        }