From 277fd3f6f70e96f4edba81dc48b309f9d47e78fb Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 2 Jul 2019 19:44:36 +0200 Subject: [PATCH] Remove cancellation token from new System.Data CloseAsync() (dotnet/corefx#39070) Affects DbDataReader and DbConnection, since these APIs are very likely to be used for cleanup only, in which case a cancellation token is an anti-pattern (similar to why DisposeAsync doesn't accept one). See discussion here: https://github.com/dotnet/standard/pull/1283#pullrequestreview-255383035 Fixes dotnet/corefx#39069 Commit migrated from https://github.com/dotnet/corefx/commit/539ed313db3ecbfb2ac9dffbb360bb7108fb4c22 --- src/libraries/System.Data.Common/ref/System.Data.Common.cs | 4 ++-- .../src/System/Data/Common/DbConnection.cs | 7 +------ .../src/System/Data/Common/DbDataReader.cs | 7 +------ 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index 617af05fdafef..8dc9c80a1f87f 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -1916,7 +1916,7 @@ public virtual event System.Data.StateChangeEventHandler StateChange { add { } r public abstract void ChangeDatabase(string databaseName); public virtual System.Threading.Tasks.Task ChangeDatabaseAsync(string databaseName, System.Threading.CancellationToken cancellationToken = default) { throw null; } public abstract void Close(); - public virtual System.Threading.Tasks.Task CloseAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; } + public virtual System.Threading.Tasks.Task CloseAsync() { throw null; } public System.Data.Common.DbCommand CreateCommand() { throw null; } protected abstract System.Data.Common.DbCommand CreateDbCommand(); public virtual void EnlistTransaction(System.Transactions.Transaction transaction) { } @@ -2062,7 +2062,7 @@ protected DbDataReader() { } public abstract int RecordsAffected { get; } public virtual int VisibleFieldCount { get { throw null; } } public virtual void Close() { } - public virtual System.Threading.Tasks.Task CloseAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; } + public virtual System.Threading.Tasks.Task CloseAsync() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public void Dispose() { } public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs index 531926c473a1a..b58290fefe3aa 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs @@ -88,13 +88,8 @@ public ValueTask BeginTransactionAsync(IsolationLevel isolationLe public abstract void Close(); - public virtual Task CloseAsync(CancellationToken cancellationToken = default) + public virtual Task CloseAsync() { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try { Close(); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReader.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReader.cs index 80d16f781a9ca..9144c2f0061fa 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReader.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReader.cs @@ -32,13 +32,8 @@ protected DbDataReader() : base() { } public virtual void Close() { } - public virtual Task CloseAsync(CancellationToken cancellationToken = default) + public virtual Task CloseAsync() { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try { Close();