Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf | Port PR #328 to improve performance in .NET Framework #1084

Merged
merged 9 commits into from
Aug 23, 2021
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