> This just a sample app I put together to show the problem I ran into, so
> some
[quoted text clipped - 4 lines]
> The Source for my test app is here:
> http://www.classicresystems.com/downloads/DownLoadExample.zip
OK, I think I know the problem. It's the same issue I had when I coding a
similar command line app that needed to stay loaded while listening for
events.
What's happening is that when you run the windows forms version the form
keeps the application loaded in memory, and so the handler can receive the
events correctly. When you run the command line version (without calling the
form), the application will run through and start off the asynchronous file
download, but then the app will finish and close (as there is nothing
keeping it open).
I'm not sure what the best option for this is. You could either:
1) Add a Console.ReadLine() statement at the bottom of your sub main:
Module Module1
Public Sub Main(ByVal ParamArray args() As String)
If args.Length > 0 Then
Dim o As New Class1
o.GetFile()
Else
Dim f As New Form1
f.ShowDialog()
End If
Console.ReadLine()
End Sub
End Module
Which will keep it alive until the user hits return, or
2) Add some kind of loop which will check a global variable that gets set
when the file has downloaded (set in your async. function):
Module Module1
Private _blnDownloadFinished As Boolean
Public Property DownloadFinished() As Boolean
Get
Return _blnDownloadFinished
End Get
Set(ByVal value As Boolean)
_blnDownloadFinished = value
End Set
End Property
Public Sub Main(ByVal ParamArray args() As String)
If args.Length > 0 Then
Dim o As New Class1
o.GetFile()
Else
Dim f As New Form1
f.ShowDialog()
End If
While _blnDownloadFinished = False
Threading.Thread.Sleep(5000)
End While
End Sub
End Module
Class1.vb:
Public Sub DownloadCompleteCallback(ByVal sender As Object, ByVal e As
AsyncCompletedEventArgs)
WriteMessage("DownloadCompleteCallback")
Module1.DownloadFinished = True
End Sub
This example is a bit dirty and doesn't check to make sure the file download
is going OK, etc, so you'll have to play with it a bit.

Signature
Leon Mayne
http://leon.mvps.org/
bedwell - 24 Jan 2008 12:37 GMT
Thank you Leon, the light went off when I read your post. Async operation
alone will not keep the app open. I appreciate your help!