Raising Events; Halting Execution

  • Thread starter Thread starter john bailo
  • Start date Start date
J

john bailo

Suppose I am writing a program that has to execute
as series of steps, but at several of the steps, I want
to wait for external events to occur.

For example ( and this relates to another of my posts ),
say I want to execute a method, then wait for a flag
file. Ok, someone suggested using FileSystemWatcher.

So then, say I do that, how do I make an internal event
halt execution on the main method, wait for the event
to be raised when the file appears and then continue
execution?
 
If you didn't mind the thread being unresponsive you could put the thread to
sleep in a loop.

Suppose that your FileWatcher code set a property when the file was
available, say _FileAvailable
then on your waiting thread you have the loop (in VB.net)

While Not _FileAvailable
system.threading.thread.currentthread.sleep(500)
end while
' Code to run then the file is found

Hope this helps

Andrew Fell-Gordon
Sound Technologies Ltd
 
Back
Top