Skip to content

Commit aa1c853

Browse files
committed
added SynchronizingObject property to FileWatcherEx
1 parent d7ef116 commit aa1c853

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

Source/DemoApp/Form1.Designer.cs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/DemoApp/Form1.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,19 @@ private void btnSelectFolder_Click(object sender, EventArgs e)
121121
FolderBrowserDialog f = new FolderBrowserDialog();
122122

123123

124-
if(f.ShowDialog() == DialogResult.OK)
124+
if (f.ShowDialog() == DialogResult.OK)
125125
{
126126
txtPath.Text = f.SelectedPath;
127+
128+
this._fw.Stop();
129+
this._fw.Dispose();
127130
}
128131
}
132+
133+
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
134+
{
135+
this._fw.Stop();
136+
this._fw.Dispose();
137+
}
129138
}
130139
}

Source/FileWatcherEx/FileWatcherEx.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.ComponentModel;
34
using System.IO;
45
using System.Threading;
56

@@ -14,9 +15,9 @@ public class FileWatcherEx : IDisposable
1415
private Thread _thread;
1516
private EventProcessor _processor;
1617
private BlockingCollection<FileChangedEvent> _fileEventQueue = new BlockingCollection<FileChangedEvent>();
17-
18-
private FileWatcher _watcher;
19-
private FileSystemWatcher _fsw;
18+
19+
private FileWatcher _watcher = new FileWatcher();
20+
private FileSystemWatcher _fsw = new FileSystemWatcher();
2021

2122
#endregion
2223

@@ -46,7 +47,12 @@ public class FileWatcherEx : IDisposable
4647
/// Gets or sets a value indicating whether subdirectories within the specified path should be monitored.
4748
/// </summary>
4849
public bool IncludeSubdirectories { get; set; } = false;
49-
50+
51+
52+
/// <summary>
53+
/// Gets or sets the object used to marshal the event handler calls issued as a result of a directory change.
54+
/// </summary>
55+
public ISynchronizeInvoke SynchronizingObject { get; set; } = null;
5056

5157
#endregion
5258

@@ -160,6 +166,7 @@ void onError(ErrorEventArgs e)
160166
this._fsw.Filter = this.Filter;
161167
this._fsw.NotifyFilter = this.NotifyFilter;
162168
this._fsw.IncludeSubdirectories = this.IncludeSubdirectories;
169+
this._fsw.SynchronizingObject = this.SynchronizingObject;
163170

164171
// Start watching
165172
this._fsw.EnableRaisingEvents = true;

Source/FileWatcherEx/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("1.1.0.0")]
36+
[assembly: AssemblyFileVersion("1.1.0.0")]

0 commit comments

Comments
 (0)