PRB: Cannot Cancel AsyncRead When Used With Local Files

ID: Q190885


The information in this article applies to:


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.

Additional query words:


Keywords          : kbActiveDocs kbIE400 kbIE401 kbVBp600 kbIE500 
Version           : WINDOWS:4.0,4.01,6.0
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: April 30, 1999