Esempio n. 1
0
            public WriteStreamedMessageAsyncResult(TimeSpan timeout, HttpOutput httpOutput, HttpResponseMessage httpResponseMessage, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.httpResponseMessage = httpResponseMessage;
                this.httpOutput = httpOutput;
                httpOutput.outputStream = httpOutput.GetWrappedOutputStream();

                // Since HTTP streams don't support timeouts, we can't just use TimeoutStream here. 
                // Rather, we need to run a timer to bound the overall operation
                if (onStreamSendTimeout == null)
                {
                    onStreamSendTimeout = new Action<object>(OnStreamSendTimeout);
                }
                this.SetTimer(timeout);

                bool completeSelf = false;
                bool throwing = true;

                try
                {
                    completeSelf = HandleWriteStreamedMessage(null);
                    throwing = false;
                }
                finally
                {
                    if (completeSelf || throwing)
                    {
                        this.sendTimer.Cancel();
                    }
                }

                if (completeSelf)
                {
                    this.Complete(true);
                }
            }