public static Task ExecuteNonQueryAsync(this SqlCommand command) { return Task.Factory.FromAsync( (cb, state) => command.BeginExecuteNonQuery(cb, state), iar => command.EndExecuteNonQuery(iar), null); }
/// <summary> /// Extends BeginExecuteNonQuery so that when a state object is not needed, null does not need to be passed. /// <example> /// sqlcommand.BeginExecuteNonQuery(callback); /// </example> /// </summary> public static IAsyncResult BeginExecuteNonQuery(this SqlCommand sqlcommand, AsyncCallback callback) { if(sqlcommand == null) throw new ArgumentNullException("sqlcommand"); return sqlcommand.BeginExecuteNonQuery(callback, null); }