SqlCommand.Cancel() documentation for 2.0 contains warning absent from 3.5; as well as vague/ambiguous warnings and contradictory example RRS feed

  • Question

  • The .NET 2.0 MSDN Documentation of the SqlCommand.Cancel method ( contains the firm warning "The Cancel method cannot be used to cancel a pending asynchronous operation."

    The updated documentation, which contains no other discernable content differences, is absent of the warning (

    I have found several reports of users using SqlCommand.BeginExecuteReaderAsync(), calling SqlCommand.Cancel(), followed by EndExecuteReader() (as per the typical convention of working with Begin/End async methods that issue an IAsyncRequest) with the expected results that the Command is cancelled and the worker thread throws an "operation has been cancelled" error during the call to EndExecuteReader() method.

    My question is: is Cancel() safe to call provided that EndExecuteReader() is called, despite the warning in the docuementaiton--OR--to safely execute a cancellable SqlCommand are you required to manually create seperate worker threads which use the blocking ExecuteReaderAsync() method as per the MSDN example?
    • Edited by S Wolfe Wednesday, April 22, 2009 12:41 PM Correction: EndExecuteReaderAsync -> EndExecuteReader
    Tuesday, April 21, 2009 10:23 PM