|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by LiebertUser in Visual Basic Programming
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?
Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
|
Imports System.IO
Module Module1
Dim WithEvents FSW As New FileSystemWatcher("O:\FTP\clp1\lsfjr009", "*.txt")
Sub Main()
Console.WriteLine("Hello World")
End Sub
Private Sub FSW_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FSW.Created
Debug.Print("test success!" & Now.ToString)
End Sub
End Module
|
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625