Npgsql.NpgsqlCommand.Cancel C# (CSharp) Method

Cancel() public method

Attempts to cancel the execution of a NpgsqlCommand.
This Method isn't implemented yet.
public Cancel ( ) : void
return void
        public override void Cancel()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Cancel");

            try
            {
                // get copy for thread safety of null test
                NpgsqlConnector connector = Connector;
                if (connector != null)
                {
                    connector.CancelRequest();
                }
            }
            catch (IOException)
            {
                Connection.ClearPool();
            }
            catch (NpgsqlException)
            {
                // Cancel documentation says the Cancel doesn't throw on failure
            }
        }

Usage Example

示例#1
0
 public void Cancel()
 {
     using (var cmd = new NpgsqlCommand("SELECT pg_sleep(5)", Conn))
     {
         Task.Factory.StartNew(() =>
         {
             Thread.Sleep(300);
             cmd.Cancel();
         });
         Assert.That(() => cmd.ExecuteNonQuery(),
             Throws.TypeOf<NpgsqlException>()
             .With.Property("Code").EqualTo("57014")
         );
     }
 }
All Usage Examples Of Npgsql.NpgsqlCommand::Cancel