Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27449

VS 2012 Can someone explain Why this doesn't work all the time.

$
0
0
I am trying to download a file in my application.. If I call it from a button or menu click event it works but in other callings it does not and returns a 0 length file and never attempts to download the file..

Code:

Private Sub ClickMenu_Click(sender As Object, e As EventArgs) Handles ClickMenu.Click
        Dim client As New WebClient()
        AddHandler client.DownloadProgressChanged, AddressOf ShowDownloadProgress
        AddHandler client.DownloadFileCompleted, AddressOf OnDownloadComplete
        client.DownloadFileAsync(New Uri("http://www.n2amg.com/files/L32LookupsUpdate.zip"), AppPath & "\Update\L32LookupsUpdate.zip")
    End Sub

This above works perfect and 100% of the time it downloads the file correctly and shows progress and completion status.

Code:

Private Sub Download()
        Dim client As New WebClient()
        AddHandler client.DownloadProgressChanged, AddressOf ShowDownloadProgress
        AddHandler client.DownloadFileCompleted, AddressOf OnDownloadComplete
        client.DownloadFileAsync(New Uri("http://www.n2amg.com/files/L32LookupsUpdate.zip"), AppPath & "\Update\L32LookupsUpdate.zip")
    End Sub

This above does not work. It returns a zero length file and never attempts to download the file as soon as it starts it exits the routine and there is no progress or completion status and no errors.

Code:

ClickMenu_Click(ClickMenu, New System.EventArgs)
Calling the working routine like above does not work either the routine returns the same zero length file and actions as above..

If I put the routine in a form by itself and call it in the load routine it works correctly..

I'm puzzled..

TIA
Rick

Viewing all articles
Browse latest Browse all 27449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>