コード例 #1
0
        public void Abort(IConnection connection, TimeSpan timeout)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            lock (this)
            {
                if (AbortResetEvent == null)
                {
                    AbortResetEvent = new ManualResetEvent(initialState: false);

                    string url = connection.Url + "abort" + String.Format(CultureInfo.InvariantCulture,
                                                                          _sendQueryString,
                                                                          _transport,
                                                                          Uri.EscapeDataString(connection.ConnectionToken),
                                                                          null);

                    url += TransportHelper.AppendCustomQueryString(connection, url);

                    _httpClient.Post(url, connection.PrepareRequest).Catch((ex, state) =>
                    {
                        // If there's an error making an http request set the reset event
                        ((ManualResetEvent)state).Set();
                    },
                                                                           AbortResetEvent);
                }
            }

            if (!AbortResetEvent.WaitOne(timeout))
            {
                connection.Trace(TraceLevels.Events, "Abort never fired");
            }
        }
コード例 #2
0
        public void Abort(IConnection connection, TimeSpan timeout)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            // Abort should never complete before any of its previous calls
            lock (_abortLock)
            {
                if (_disposed)
                {
                    throw new ObjectDisposedException(GetType().Name);
                }

                // Ensure that an abort request is only made once
                if (!_startedAbort)
                {
                    _startedAbort = true;

                    string url = connection.Url + "abort" + String.Format(CultureInfo.InvariantCulture,
                                                                          _sendQueryString,
                                                                          _transport,
                                                                          Uri.EscapeDataString(connection.ConnectionToken),
                                                                          null);

                    url += TransportHelper.AppendCustomQueryString(connection, url);

                    _httpClient.Post(url, connection.PrepareRequest).Catch((ex, state) =>
                    {
                        // If there's an error making an http request set the reset event
                        ((HttpBasedTransport)state).CompleteAbort();
                    },
                                                                           this);

                    if (!_abortResetEvent.WaitOne(timeout))
                    {
                        connection.Trace(TraceLevels.Events, "Abort never fired");
                    }
                }
            }
        }