Npgsql.NpgsqlConnector.CancelRequest C# (CSharp) Method

CancelRequest() private method

private CancelRequest ( ) : void
return void
        internal void CancelRequest()
        {

            NpgsqlConnector cancelConnector = new NpgsqlConnector(settings, false, false);

            cancelConnector._backend_keydata = BackEndKeyData;

            try
            {
                // Get a raw connection, possibly SSL...
                cancelConnector.CurrentState.Open(cancelConnector, cancelConnector.ConnectionTimeout * 1000);

                // Cancel current request.
                cancelConnector.CurrentState.CancelRequest(cancelConnector);
            }
            finally
            {
                cancelConnector.CurrentState.Close(cancelConnector);
            }

        }

Usage Example

示例#1
0
        ///<summary>
        /// This method is responsible to handle all protocol messages sent from the backend.
        /// It holds all the logic to do it.
        /// To exchange data, it uses a Mediator object from which it reads/writes information
        /// to handle backend requests.
        /// </summary>
        ///
        internal IEnumerable <IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context)
        {
            try
            {
                // Flush buffers to the wire.
                context.Stream.Flush();

                // Process commandTimeout behavior.

                if ((context.Mediator.BackendCommandTimeout > 0) &&
                    (!CheckForContextSocketAvailability(context, SelectMode.SelectRead)))
                {
                    // If timeout occurs when establishing the session with server then
                    // throw an exception instead of trying to cancel query. This helps to prevent loop as
                    // CancelRequest will also try to stablish a connection and sends commands.
                    if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState)))
                    {
                        try
                        {
                            context.CancelRequest();

                            ProcessAndDiscardBackendResponses(context);
                        }
                        catch (Exception)
                        {
                        }
                        // We should have gotten an error from CancelRequest(). Whether we did or not, what we
                        // really have is a timeout exception, and that will be less confusing to the user than
                        // "operation cancelled by user" or similar, so whatever the case, that is what we'll throw.
                        // Changed message again to report about the two possible timeouts: connection or command
                        // as the establishment timeout only was confusing users when the timeout was a command timeout.
                    }

                    throw new NpgsqlException(resman.GetString("Exception_ConnectionOrCommandTimeout"));
                }

                switch (context.BackendProtocolVersion)
                {
                case ProtocolVersion.Version2:
                    return(ProcessBackendResponses_Ver_2(context));

                case ProtocolVersion.Version3:
                    return(ProcessBackendResponses_Ver_3(context));

                default:
                    throw new NpgsqlException(resman.GetString("Exception_UnknownProtocol"));
                }
            }
            catch (ThreadAbortException)
            {
                try
                {
                    context.CancelRequest();
                    context.Close();
                }
                catch {}

                throw;
            }
        }
All Usage Examples Of Npgsql.NpgsqlConnector::CancelRequest