B
Bedwell
Ok, I’m using the method DownloadFileAsync to download a large file and I
also use the DownloadProgressChanged event to show users how far along they
are in downloading the file. I put this into a WinForms application, make a
call to the download file method (behind a button click event) and the
download works fine. If I call the download file method from Commandline
switch in the WinForms app it fails, it starts to download the file but never
finishes. Any idea why running a WinForms from a commandline would cause this
function not to work?
Example: Call GetFile from Button click, it works. Call GetFile from
commandline switch passed into the same app, it doesn’t download. Note: The
file being downloaded is large.
Public Function GetFile() As Boolean
Try
Dim client As New WebClient
Dim fld As DirectoryInfo
Dim fil As FileInfo = New FileInfo("C:\LocalFileName.exe")
fld = fil.Directory
client.Credentials = CredentialCache.DefaultCredentials
If fld.Exists = False Then
Dim Msg As String = "Destination folder for setup file does
not exist."
Throw New Exception(Msg)
End If
AddHandler client.DownloadProgressChanged, AddressOf
DownloadProgressCallback
Dim uri As Uri = New
Uri("http://www.SomeSite.com/downloads/ServerFileName.exe") ' This file is
large (100 Megabtyes)
client.DownloadFileAsync(uri, fil.FullName)
Catch Err As Exception
WriteMessage(Err.Message & vbTab & Err.StackTrace)
End Try
End Function
Public Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As
DownloadProgressChangedEventArgs)
WriteMessage("DownloadProgressCallback")
End Sub
also use the DownloadProgressChanged event to show users how far along they
are in downloading the file. I put this into a WinForms application, make a
call to the download file method (behind a button click event) and the
download works fine. If I call the download file method from Commandline
switch in the WinForms app it fails, it starts to download the file but never
finishes. Any idea why running a WinForms from a commandline would cause this
function not to work?
Example: Call GetFile from Button click, it works. Call GetFile from
commandline switch passed into the same app, it doesn’t download. Note: The
file being downloaded is large.
Public Function GetFile() As Boolean
Try
Dim client As New WebClient
Dim fld As DirectoryInfo
Dim fil As FileInfo = New FileInfo("C:\LocalFileName.exe")
fld = fil.Directory
client.Credentials = CredentialCache.DefaultCredentials
If fld.Exists = False Then
Dim Msg As String = "Destination folder for setup file does
not exist."
Throw New Exception(Msg)
End If
AddHandler client.DownloadProgressChanged, AddressOf
DownloadProgressCallback
Dim uri As Uri = New
Uri("http://www.SomeSite.com/downloads/ServerFileName.exe") ' This file is
large (100 Megabtyes)
client.DownloadFileAsync(uri, fil.FullName)
Catch Err As Exception
WriteMessage(Err.Message & vbTab & Err.StackTrace)
End Try
End Function
Public Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As
DownloadProgressChangedEventArgs)
WriteMessage("DownloadProgressCallback")
End Sub