filesystemwatcher

Unit-testing FileSystemWatcher: How to programatically fire a changed event?

[亡魂溺海] 提交于 2020-02-01 21:42:26
问题 I have a FileSystemWatcher watching a directory for changes, and when there's a new XML file in it, it parses that file and does something with it. I have a few sample XML files in my project that I am using for unit-testing purposes for the parser I wrote. I'm looking for a way to use the sample XML files also to test the FileSystemWatcher . Is it possible to programatically create an event (somehow involving the XML file) in order to trigger the FSW.Changed event? 回答1: I think that you are

Is there a simple way to avoid or stop FileSystemWatcher raise event twice in C#?

≯℡__Kan透↙ 提交于 2020-01-25 07:36:09
问题 I want to know what how to avoid or stop FileSystemWatcher raise event twice in C#? I have a solution that will detect everytime if there is newly created xml file from a folder. I test my application using creating xml file using notepad but from the listbox it displays twice. How can I fix this issue? Here is my code: private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e) { try { fileSystemWatcher1.EnableRaisingEvents = false; listBox1.Items.Add(e.FullPath);

FileSystemWatcher and GUI

▼魔方 西西 提交于 2020-01-24 17:55:06
问题 I have a little problem with my WPF project and the FileSystemWatcher class. In my MainWindow class the watcher begins to watch a folder when Button Start is clicked in the UI. Everything works without any problems - the watcher recognizes correctly when a file is created. But while watcher is waiting it is not possible for user to do anything in the UI. It should be possible for nexample to click Stop... private void Start_Click(object sender, RoutedEventArgs e) { rdbTextBox.Document.Blocks

FileSystemWatcher and windows 7

可紊 提交于 2020-01-20 21:38:27
问题 I am writing a tool that monitors a network directory and is running off of a Windows Server 2008 machine, the OnChanged event for the FileSystemWatcher is being fired correctly from files placed on the network drive by any computer that is not using Windows 7, for some reason if the amount of files copied is more than 19 on a windows 7 computer (at once) then no events are fired although it works if files are done individually. Is there a workaround for this or is that just how the Windows 7

Catching exceptions thrown by the FileSystemWatcher listener thread

混江龙づ霸主 提交于 2020-01-15 10:59:06
问题 I am trying to figure out a way to catch exceptions thrown by FileSystemWatcher these seem to happen randomly as I have noticed from the crash reports logs for my software. The crash is not frequent as it only happened twice last month but its annoying and I would love to fix it. The exception in question seems to be related to files having invalid characters in their paths. I am not sure if that is the case or if the event raised is malformed. So far all I know is the stack trace of the

C# : file copy notifying [closed]

一曲冷凌霜 提交于 2020-01-11 10:53:27
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . hi i am creating a c# application that monitor the files that has been copied , the aim of program is to alert user that there is a file has been copied , i know the file system watcher class , but it has only 4 events , change or create or delete or rename , is there a way to know if file has been

What's the best practice to recover from a FileSystemWatcher error?

一个人想着一个人 提交于 2020-01-11 08:42:06
问题 After a FileSystemWatcher.Error event was raised, I have no clue about what to do next. The exception can be a [relatively] minor one, such as too many changes at once in directory which doesn't affect the watcher's watching process, but it can also be a big issue - such as the watched directory being deleted, in which case the watcher is no longer functional. My question is what is the best way to handle the Error event? 回答1: Depends on the error surely? If it is too much data because the

How to monitor process' IO activity using C#?

旧巷老猫 提交于 2020-01-11 06:06:51
问题 Using FileSystemWatcher we can monitor the IO activity of a particular file system, but is there anyway to know that which one of the running processes is causing that IO? More specifically, suppose a running process viz. abc.exe is creating a file text.txt on drive D. We can monitor that a file named text.txt has been created in drive D using FileSystemWatcher, but can we determine programmatically that a process named abc.exe is creating that particular file in drive D? 回答1: handle.exe from

How to monitor process' IO activity using C#?

旧街凉风 提交于 2020-01-11 06:05:13
问题 Using FileSystemWatcher we can monitor the IO activity of a particular file system, but is there anyway to know that which one of the running processes is causing that IO? More specifically, suppose a running process viz. abc.exe is creating a file text.txt on drive D. We can monitor that a file named text.txt has been created in drive D using FileSystemWatcher, but can we determine programmatically that a process named abc.exe is creating that particular file in drive D? 回答1: handle.exe from

get filesystemwatcher events to occur on main UI thread

北慕城南 提交于 2020-01-10 04:19:33
问题 Can i get filesystemwatcher events to occur on the main UI thread ?. Currently file changes are fired off on their own threads. 回答1: Simply set the FileSystemWatcher.SynchronizingObject property to the form instance. Same thing as calling BeginInvoke() but done automatically for you. Boilerplate code: public Form1() { InitializeComponent(); fileSystemWatcher1.SynchronizingObject = this; } 回答2: this.BeginInvoke((MethodInvoker)(() => SomeMethod())); // Check files in the Main thread otherwise