PRB: Cannot Cancel AsyncRead When Used With Local Files (190885)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q190885

SYMPTOMS

When using AsyncRead from a ActiveX Document or an ActiveX Control project running under Internet Explorer 4.x to download a local file, you cancel the operation by calling CancelAsyncRead. CancelAsyncRead does not work for local files.

CAUSE

Reading a local file is a Synchronous operation. For this reason the call to AsyncRead is completed before any subsequent lines of code are executed.

MORE INFORMATION

Steps to Reproduce Behavior



  1. Create a blank ActiveX Document project in Visual Basic 6.0.
  2. Insert the following code in the project:
    Private Sub UserDocument_AsyncReadComplete(AsyncProp as
       AsyncProperty)
        MsgBox "CancelAsyncRead didn't work. Downloaded " & _
               AsyncProp.BytesRead & " Bytes"
    End Sub
    
    Private Sub UserDocument_Show()
       'use a large file here
       AsyncRead "c:\windows\system\mshtml.dll", vbAsyncTypeByteArray
       MsgBox "Notice that CancelAsyncRead hasn't been called yet!"
       CancelAsyncRead
    End Sub
    						
  3. Run your project and load the Visual Basic Document in Internet Explorer 4.x
You will see the MsgBox in AsyncReadComplete is shown before the MsgBox in UserDocument_Show(). This means that the AsyncReadComplete event is fired before CancelAsyncRead could be called.

Modification Type:MajorLast Reviewed:12/10/2003
Keywords:kbActiveDocs kbprb KB190885