473,508 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UI Thread and FileSystemWatcher.WaitForChanged method

The documentation specifies that the WaitForChanged method should not be
called on the UI thread or it will freeze the UI thread. So, I have
started it in a thread seperate from the main form's thread. The
WaitForChanged event will wait infinitely until a file is created, but
the user needs to be able to stop the application from running and so I
need to stop that thread waiting for the file. I have hookde up a
ManualResetEvent to the method calling WaitForChanged, but it only
checks if the thread has been stopped after the call to WaitForChanged
returns. How can I force the WaitForChanged method to come back before
a file is found?
thanks!
Nov 16 '05 #1
1 6099
Hi Matthew,

Call the Interrupt method on the thread that is waiting for the file changes
(see class Thread, method Interrupt in your documentation). This will cause
the WaitForChanged method to throw a ThreadInterruptedException. This
effectively unblocks your call.

HTH,
Tom T.

"Matthew Wieder" wrote:
The documentation specifies that the WaitForChanged method should not be
called on the UI thread or it will freeze the UI thread. So, I have
started it in a thread seperate from the main form's thread. The
WaitForChanged event will wait infinitely until a file is created, but
the user needs to be able to stop the application from running and so I
need to stop that thread waiting for the file. I have hookde up a
ManualResetEvent to the method calling WaitForChanged, but it only
checks if the thread has been stopped after the call to WaitForChanged
returns. How can I force the WaitForChanged method to come back before
a file is found?
thanks!

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1013
by: Balu | last post by:
Hi, I am using the FileSystemWatcher object to watch for a specific file being created in a directory (with a timeout): fileWatcherResult = fileWatcher.WaitForChanged...
0
1739
by: Erik Herje via .NET 247 | last post by:
Hi, I have a Windows Service written in C# whos purpose is to sniff a folder to look for changes in the folder. If a file is created or changed, it should get its name and start an object the...
2
4491
by: John Lee | last post by:
Hi, I wrote a small program that copy a list of files to a specified folder one by one, i.e. this app will copy one file into the specified folder and wait until it's consumed (deleted) then...
3
2693
by: Krish | last post by:
Hello Gurus, Pardon me for asking dumb question... I wrote small csharp program to watch a folder for any created text file... When i try to run through debugger and stop after "...
3
2934
by: Stephen Miller | last post by:
I have an ASP.Net application that sends a NetworkStream to a .Net Service, which has a TcpListener listening on a port for the ASP.Net client. When it receives a request it creates a new thread...
1
5410
by: Megan | last post by:
I have a windows service that monitors a folder. I have a routine to process XML files whenever a new file gets created (in the folder that the Filesystemwatcher is monitoring.) Since the files...
10
1681
by: Kai Thorsrud | last post by:
Hi i'm an event Noob and i'm calling a class from my main module console app like this. I'm sorry if this is a lot of code to read but i can't see the error according to my book. Thanks a LOT. ...
1
10370
by: Abel Chan | last post by:
Hi there, I was trying to write a simple NT services using .NET 2.0 and fileSystemWatcher control. The goal is to poll documents from a watch directory and ftp them to a remote web site. I...
4
1692
by: Smithers | last post by:
Does the FileSystemWatcher class, when enabled, spawn a new thread for itself? I googled and somehow just found people having random problems with the FileSystemWatcher class and the MSDN docs....
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.