Overusing System.IO.FileSystemWatcher

May 11, 2011

I'm planning out a filesystem tools application. I'd like to use a collection of FileSystemWatcher to keep an eye on every drive while the application is active, so that if the filesystem topography changes the change event can update the UI (it's

either that or spawn extra threads to constantly loop through checking if drives have been added/removed and then drilling through every drive path to see if folders/files changed - I really don't want to use extra threads).

I don't use FileSystemWatcher much and I'm wondering how much of a resource hog this is likely to turn into. For example, I have 1 500GB and 2 1TB hard drives and I have 2 CD/DVD drives in my system - I also use external IDE and SATA bays to attach

extra drives ranging from 20GB to 2TB at a time, and I'd be using a Collections.Generic.List of FileSystemWatcher to spawn a new watcher for each drive, adding and removing FileSystemWatcher instances as drives are added and removed.

At that point I'm not entirely sure whether a FileSystemWatcher pointed at the root of a physical drive will actually monitor the entire sub-filesystem for changes, and even if it's capable of that exactly how much system overhead am I going to be sucking in?

View 4 Replies


ADVERTISEMENT

FTP And FileSystemWatcher

Feb 20, 2012

I have my application watching my desktop, pictures, music, and document folders.[code]What would I need to put into logrename() in order for it to automatically upload the renamed file onto my server?

View 5 Replies

FileSystemWatcher Is Not Working?

Jul 31, 2010

I added FileSystemWatcher in Form1_Load like this -

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
....................

[code]....

View 2 Replies

Can't Get FileSystemWatcher To Work

Apr 7, 2011

I can't seem to get a FileSystemWatcher to work, this is what I currently do.

Private Sub FileSystemWatcher1_Changed(sender As System.Object, e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
MsgBox("Directory has changed")
End Sub

I have the filesystemwatcher path in my desktop. But when I create, re-name or delete something in the desktop it dosn't do anything, not even giving an error. I filter FileName, DirectoryName and LastWrite (the defaults).

The FileSystemWatcher have the EnableRaisingEvents set to true. So don't really know what the problem is.

I've tried google without any luck, all I found was people having problem that the FileSystemWatcher executed twice.

So do I have to do anything more on the code to get it to work?

View 1 Replies

FileSystemWatcher And Get MD5 Data?

Mar 23, 2010

I have a FileSystemWatcher in my project and when Created new file, i can get MD5 value of the new file, but sometimes error occurred while getting MD5 value, my code is like this

Private Sub FileSystemWatcher_Changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles SystemScanner.Changed
Try

[code]....

That error is "Access Denied", i think function must be wait for done the progress, how can resolve this problem ?

View 3 Replies

FileSystemWatcher Freezing GUI?

May 25, 2010

I have a FileSystemWatcher monitoring a folder, and when many files are cut and pasted into the folder, the GUI freezes, as the 'Changed' event is fired over and over. Any way to deal with this?

View 1 Replies

VS 2008 - FileSystemWatcher Does Nothing

Oct 9, 2009

I've been trying to get filesystemwatcher to work in my application with no luck. I've been able to modify the example on MSDN and have it work very well, but not when I try to use it in my own program. [Code]

If you compare it to the example, there really is very little difference, at least to me. "loadlist" is the equivalent of "main" in the example, "watchfile" is the equivalent of "run", and "OnChanged" is the same as in the example, but performing different actions. Right now its not doing anything. If I remove "Shared" from the subs then it works if the file changes once, but after that it does nothing. (I must admit I don't really know what making a sub "Shared" does).

View 3 Replies

VS 2008 FileSystemWatcher?

Jan 4, 2010

I have a FileSystemWatcher tool on my form Watching 'C:' and i am now the FileCreated Code

Private Sub FileSystemWatcher1_Created(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
Dim Name As String

[code].....

View 2 Replies

FileSystemWatcher & FTP Folders - Remote Or Loc?

Jul 29, 2011

I've written a nice service that monitors our FTP folder, then sends out email notifications to the respective Sales / Customer Service reps associated with the client whose folder has been modified.Working great! ...until a CSR asked if there was any way to make is so that email notifications only get sent out if if's the customer making changes to the folder, not someone internal adding / deleting files to the FTP folder...

So, my question is this - is there any way, and if there are multiple ways, what's the best way to tell WHO is making changes to an FTP folder? is there a way to capture an IP address?Being relatively new to .NET (all of about 8 months sporadically...) I'm hoping that a veteran that knows more about .NET than I will get me going in the right direction!

View 14 Replies

FileSystemWatcher - Multiple Zip Files?

Sep 13, 2010

I am in the process of writing a windows service that will be replacing a vbscript that runs via a scheduled task currently. It currently runs on 350 kiosk machines in 350 different locations.Here is what the vbscript currently does:

1. The machine receives a ZIP file in the RECEIVE directory. Configuration_09122010_1234.zip. This file contains software configuration files that need to be copied to specified folders on the machine and to another machine on the local LAN where this kiosk is located.

2. The zip file is extracted to a folder with the same name as the zip file.Inside the zip file is an instruction file (.txt) and files that are referenced in the instruction file.

3. Opens the instruction file and performs the instructions in the file. Example: (this would copy pricingfile1.dbf to \mymachinecapplication1pricing, and then execute softwaresoftwarepatch1.exe which is located in \mymachinecpatches)

pricingfile1.dbf, \mymachinecapplication1pricing, copy
softwarepatch1.exe, \mymachinecpatches, run

4. Once all of the actions in the instructions file are completed, the folder where the zip file was extracted is deleted and the zip file is renamed to configuration_09122010_1234.zip.applied to show that it was processed by the script. Also, because the script is a scheduled task, this ensures that the file is not applied more than 1 time.

So I have started writing the service using the FileSystemWatcher. Basically I look in the receive folder for any file that looks like Configuration_MMddyyyy_*.zip and unzip it to a folder of the same name.

1. I have been doing some reading about the FileSystemWatcher Created event.I read an article about how the Created event fires as soon as the first byte is written but doesn't necessarily mean that the complete file has arrived at the machine. A post I read involved a .csv file and it mentioned that you try to open the file and catch any errors - if you cannot open the file, it hasn't arrived yet. This makes sense to me but I don't know what the equivalent would be to a zip file. It's not the same as opening a txt or csv file.

2. There are times that we send more than 1 configuration file in the same day, or even, at the same time. Above I mentioned the name was Configuration_<date>_1234.zip. The 1234 is a sequence number, always incremented. The idea is for 1234 to be applied before 1235 and 1236. So if I had 2 files sent *at the same time* and I want them to apply in order, how would I do this? I thought about when I am applying 1 file to stop looking for changes until after the apply process is completed, but then I *think* I would miss any file that arrived while I EnableRaisingEvents = false?

View 1 Replies

FileSystemWatcher - Multithreading Inputs?

Feb 11, 2012

I am developing an FTP program which: Watches a folder. If a new file is dropped there then upload it. Tells user if uploading and when complete. All the above works, however I wan to add the items to a listbox that are being uploaded. So if I dropped 3 items there it would look like :

Upload Listbox:
cake.jpg
myExcelFile.xls
woot.docxAnd as each one is done, or new files are added it removes them or adds them.

I tried using que, but with no luck as the program just hangs whilst it uploads. So I had a search and looked into multithreading and I tried to implement it, but I can't get it to work as it gives me some 'delegate signature' related error message as you can't pass in values when trying to use 'AddressOf'.

Here is my code for the The .created sub:
Public Sub FSystemWatcher_Created(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FSystemWatcher.Created
'if any file created add fullpath to the listbox
ChangeLog.Items.Add("Created: " & e.Name)
QueueListBox.Items.Add(e.Name)
[Code] .....

View 20 Replies

Filesystemwatcher - Watch Folder In WPF?

Jan 22, 2012

I'm having a problem trying to work out how to watch a folder for changes. This is how far I've got:

Class MainWindow
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As

[Code]....

The problem is when a change occurs in the folder the program exits with no error code. I've read a few related posts and I know it has something to do with thread safety. However I've no idea how to make this program "thread safe".

View 1 Replies

FileSystemWatcher And IO.Directory.Move?

Jul 11, 2009

I've been trying to figure this out, but have had no luck...Using FileSystemWatcher to monitor a folder and subfolders.I've got everything working fine (inluding cut-paste of a folder), the problem i'm having with is if a directory is moved, there is no way for me to get the contents of the moved folder...and the only event that is fired is a "Changed" event...no rename, nothing else.From the MSDN website:Copying and moving foldersThe operating system and FileSystemWatcherobject interpret a cut-and-paste action or a move action as a rename

View 12 Replies

VS 2005 FileSystemWatcher's Cut And Paste

May 14, 2010

I have a program which has FSW (File System Watcher) and it monitor "Folder ". When the new file has been created, it will move this file to "Folder B". During testing what I found is: The program works OK if I put the file in "Folder " as cut and paste from other location. However, if I copy and paste the file in "Folder ", the moving function got error and said The process cannot access the file 'D:watchCopy of Tester.txt' because it is being used by another process.

My FSW watch "Changed" only and the NotifyFilters are DirectoryName, Attributes, LastAccess and FileName. I refer the sample from MSDN and put a file copying function only. [MSDN Sample Link] (FYI: I did a search in the forum and didn't found the above solution. So, I assumed this ques has not been asked and therefore I create a new threat. If there was an answer already posted,

View 2 Replies

VS 2008 FileSystemWatcher Error?

Mar 19, 2009

I am getting the following error, when I create a file in the folder that I am watching using FileSystemWatcher Control.Message="Cross-thread operation not valid: Control 'txt_FolderActivity' accessed from a thread other than the thread it was created on." Source="System.Windows.Forms"

View 11 Replies

.net - FileSystemWatcher Changed Event Not Being Raised?

Apr 29, 2009

I'm working on a Windows Service that watches a few folders for changes, creations, and deletions. It all works well with the exception of one watcher that watches a single file (XML File with Configuration Settings) for minor changes.

I tried taking the Windows Service code and putting it into a simple windows application with start/stop buttons for the filesystem watchers and stepped through it. It never detects the file change of the XML config file. The changes are indeed occurring and the "Date Modified" of the file is updating.

XmlEventReferences = New System.IO.FileSystemWatcher()
XmlEventReferences.Path = "C:XmlReferences"
XmlEventReferences.Filter = "*.xml"

[Code].....

View 3 Replies

.net - FileSystemWatcher Multiple Change Events?

Jan 16, 2009

I have the following code:

Imports System.IO
Public Class Blah
Public Sub New()
InitializeComponent()

[code]....

When I run it and save changes to a file on my C drive, the code works great, except it executes the watcher_Changed() method four times. The changeType is "4" every time.

View 14 Replies

Cannot Monitor Word Docs Using FileSystemWatcher

Sep 27, 2011

I have a folder that contains multiple word documents. I need to monitor this folder for any changes in these word documents. I am facing the following problems.

File system watcher never reports the exact name of file being changed. For example for file abc.doc, it reports "~$abc.doc is changed" on first save.For all subsequent saves to that file, OnChanged event in the following code is not called. When I changed the filter to watcher.Filter = ".", I found that for subsequent saves, it reports "~WRL0001.tmp is changed".

So the bottom line is that I never know the exact name of the file changed.[code]...

View 2 Replies

Comclass Error When Connected To VB6, Filesystemwatcher?

Dec 13, 2010

When I run the code to setup the watcher everything run ok. When A new file is detected, I get the messagebox with no problem. After I click 'ok', the vb6 app that called this crashes with no error.[code]......

View 12 Replies

FileSystemWatcher / How To Know Which Process Made Change

Jul 7, 2011

is it possible to get the name of the process that caused the change in the filesystem?i want to do this programmatically [ie, i can't use any external 3rd party tools like handle]

View 1 Replies

FileSystemWatcher And Locked Image Files?

Apr 13, 2012

I have a filesystemwatcher waiting for .jpg files to arrive from the camera.he file system watcher invokes a delegate (it works but is that the proper way to handle it?) sub that does a couple of things:1. Adds the just arrived file name to a table2. Attempts to display the image in a picturebox on the form. When it displays the image it imprints some information on the image that the user has entered on the screen. I use a file stream to retrieve the image.The problem is, I'm getting a file in use orror on the "Img = ystem.Drawing.Image.FromStream(fs)"statement. Not all the time. Sometimes I can add three or four files to the folder in rapid succession with no issue. But then out of the blue the error will occur. Sometimes it's there to stay but other times it will go away and allow me to add morefiles.

View 2 Replies

FileSystemWatcher And Save Excel Files

Aug 21, 2011

I am trying to write an app that monitora a folder, and subfolders, amd makes a copy of any file that gets saved there, (or renamed, moved etc). Filesystemwatcher does a pretty good job of it, untili someone saves an Excel spreadsheet. Excel does about 9 different file system operations just to save the file. What happens is I get events for tempo files being saved, then renamed, or deleted in a very quick succession. All I want is the final spreadsheet, but these changes happen so quickly is causes my app to crash. Anybiody have any thoughts on how to hendle this?

View 3 Replies

FileSystemWatcher Not Detecting Change In File?

Oct 17, 2010

I've written the following code. It works fine for creating, deleting and renaming files. However when I set a file to read only, or modify the file (i.e open it in notepad and change the contents) nothing happens (it doesn't hit the change breakpoint)

I have the following

VB.NET
Private fsw As FileSystemWatcher
Public Sub WatchFiles(ByVal tblMappings As DataSet)

[code]....

View 3 Replies

FileSystemWatcher Quits Monitoring During Execution?

Mar 30, 2010

FileSystemWatcher quits monitoring during execution?

View 1 Replies

Filesystemwatcher That Watches A Couple Of Folders

Oct 22, 2009

I have a filesystemwatcher that watches a couple of folders! The files coming to the watched folder are coming from a server. And for some reason the created event is not raised..If i move the files for a sec from the watched folder to a another folder and then copy them back to the watched folder it all works fine! Strange.So if the created event is raised from the same computer that the service is installed on it works great, but not if the files are coming from another computer.

View 2 Replies

FileSystemWatcher Won't Fire For Directory Events?

Mar 9, 2010

I trying to be notified when a directory is created, deleted, renamed or moved. The VB.NET code below only shows the Rename event.

Imports System.IO
Imports System.Threading
Public Class Form1

[Code].....

View 3 Replies

Forms :: Filesystemwatcher Firing Files Twice?

May 29, 2011

ive just finished writing a file in VB 2010 and im using filesystemwatcher but ive found a problem whereas the filesystemwatcher fires the target twice everytime there is a change to the file.

ive looked around and found it to be a problem but cant seem to find a cure

View 1 Replies

Set The FileSystemWatcher.Filter To Check Only Two Files?

Jun 11, 2011

How do you set the FileSystemWatcher.Filter to check only two files.

Here's my code that doesn't even work.

watcher.Filter = "*.txt|*.ini"

View 5 Replies

Watch The File Action By FileSystemWatcher

Apr 5, 2010

We can watch the file action by FileSystemWatcher but it give us to only create,rename,delete or replace action report, can we get file access action ? for example when user double click any file? or when run any application?

View 8 Replies

Will FileSystemWatcher Process Multiple Files At Once?

Jun 1, 2009

I have a Windows service that is watching a folder for files that will be placed there.(Created in Visual Studio 2005.)The files each represent a transaction, and the transactions have to be kept in order.As I process each file (transaction), I want to forward it to someone else.(The someone else wants them kept in order.)It looks like I can't paste multiple files into a folder simultaneously and still be sure that they will be processed in the order of the original date and time they were created.Nor can I be sure that they would be read in name order.(FileSystemWatcher would grab them in any old order it chose.)So I think I will have to move the files into the folder one at a time, in the proper sequence.But I'm wondering if I could get into a "racing" situation.

When FileSystemWatcher detects a file in a folder, it creates a new thread for your event handler to operate on.If it detects a second file while still processing the first file, would it then create yet another thread?If that is the case, then if File1.xml takes longer to process than File2.xml, it seems like File2.xml might finish first, resulting in my transactions getting out of order.In my own experiments,I have not seen evidence that multiple files are really processed simultaneously.I write messages to a log file as I process each transaction, and I never see messages from File1.xml's processing intermingled with File2.xml's messages.This seems to be true even when I paste both files into the folder simultaneously.it only keeps one event-handling thread going at a time, and queues up the events as they come, processing them on that single thread.Otherwise, I'll have to do something to ensure they are kept in order.

View 9 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved