do events is only valid with forms..
so this should work.
Main Topics
Browse All TopicsI'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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
wrmichael, yes, I will want to be able to terminate it. Just pressing <ENTER> and having it say 'Goodbye World' would be perfect for my learning example.
I've written one service with good results and agree with you that a service would be suitable except for one little 'GOTCHA'. The drive share I'm monitoring is a secured network drive so someone would need to be logged in, with permission to the network share. A service might come later, but right now I don't have a problem with having it run under a user's login.
wrMichael, I know I just need to try this but your answers are coming pretty fast so I thought I would ask while your at your keyboard.
If I do the sleep ((32000) = 32 seconds I think) will my event still fire while the sleep thread is running? Or will my event be queued and then run when the Doevents executes?
I would suggest you not use a Console app... =\
If you want a formless app start with a WinForms project. Uncheck the "Enable Application Framework" box in Project --> Properties and add a Module with a Sub Main in it. Then Inherit a Class from ApplicationContext and pass your instance of that to Application.Run() in Sub Main(). This will allow you to have a formless app with a message pump (that can receive events) that doesn't die and doesn't have a klunky while loop.
Idle_Mind, that works in as much as it doesn't just quit running after going through sub main and my filesystemwatcher does respond to events but how do I get it to open a command window and write to that window (much like console.writeline does).
If I doubleclick the example app it just invisiblly starts even though I have a console.writeline statement.
If I start it from the command line the console.writeline still doesn't write anything (although it doesn't blow up so its writing to something).
Its my bosses requirement that this little app just be a command line app. Any thoughts?
Thanks
Business Accounts
Answer for Membership
by: wrmichaelPosted on 2009-10-22 at 10:23:45ID: 25636662
use a do while loop and put in a thread.sleep and a doevents.