Skip to content
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