Skip to content

Commit

Permalink
Perf | Port PR #328 to improve performance in .NET Framework (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra committed Aug 23, 2021
1 parent 5f6478a commit 241631a
Show file tree
Hide file tree
Showing 3 changed files with 642 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public sealed class SqlCommand : DbCommand, ICloneable
/// Internal flag for testing purposes that forces all queries to internally end async calls.
/// </summary>
private static bool _forceInternalEndQuery = false;
#endif
#endif
internal static readonly Action<object> s_cancelIgnoreFailure = CancelIgnoreFailureCallback;

// devnote: Prepare
// Against 7.0 Server (Sphinx) a prepare/unprepare requires an extra roundtrip to the server.
Expand Down Expand Up @@ -914,6 +915,12 @@ protected override DbParameterCollection DbParameterCollection
return Parameters;
}
}

internal static void CancelIgnoreFailureCallback(object state)
{
SqlCommand command = (SqlCommand)state;
command.CancelIgnoreFailure();
}

internal void CancelIgnoreFailure()
{
Expand Down Expand Up @@ -2972,7 +2979,7 @@ private Task<int> InternalExecuteNonQueryAsync(CancellationToken cancellationTok
source.SetCanceled();
return source.Task;
}
registration = cancellationToken.Register(CancelIgnoreFailure);
registration = cancellationToken.Register(s_cancelIgnoreFailure, this);
}

Task<int> returnedTask = source.Task;
Expand Down Expand Up @@ -3069,7 +3076,7 @@ private Task<SqlDataReader> InternalExecuteReaderAsync(CommandBehavior behavior,
source.SetCanceled();
return source.Task;
}
registration = cancellationToken.Register(CancelIgnoreFailure);
registration = cancellationToken.Register(s_cancelIgnoreFailure, this);
}

Task<SqlDataReader> returnedTask = source.Task;
Expand Down Expand Up @@ -3215,7 +3222,7 @@ private Task<XmlReader> InternalExecuteXmlReaderAsync(CancellationToken cancella
source.SetCanceled();
return source.Task;
}
registration = cancellationToken.Register(CancelIgnoreFailure);
registration = cancellationToken.Register(s_cancelIgnoreFailure, this);
}

Task<XmlReader> returnedTask = source.Task;
Expand Down
Loading

0 comments on commit 241631a

Please sign in to comment.