I'm writing my first console application in VB 2005. Fortunately, its also likely to be the simplest application that I've ever created.
I want to watch a folder using the .NET filesystemwatcher. My question is, how do I keep the program 'alive'? See my extremely simple example below. This is just the skeleton but the complete app won't do much more than just react to the FileSystemWatcher_Created event and copy a file.
When I run the program, it prints 'Hello World' and instantly closes. Fair enough - but I just want it to spin its wheels and let the Filesystemwatcher and its event do all the work. For my forms based apps this has never been an issue because as long as I have a form, my app is open.
I guess I don't understand the life and scope of objects very well. I mean, if a form object has enough sense to stay open, why won't a filesystemwatcher object stay open?
Dim WithEvents FSW As New FileSystemWatcher("O:\FTP\clp1\lsfjr009", "*.txt")
Private Sub FSW_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FSW.Created
Debug.Print("test success!" & Now.ToString)