G
Guest
Hello,
I have built a .NET remoting solution (SingleCall) that writes a file to
disk, then waits for a second file in a specified folder (using the
FileSystemWatcher.WaitForChanged method). When the component is called by two
peers at the same time, two FileSystemWatchers are created (one for each
peer). They are both monitoring the same path (but for different files -
using different filters). The following code illustrates the scenario:
using System;
using System.IO;
using System.Threading;
class clsMain {
static void Main() {
Thread thread1 = new Thread(new ThreadStart(t1));
Thread thread2 = new Thread(new ThreadStart(t2));
thread1.Start();
thread2.Start();
Console.ReadLine();
}
static void t1() {
FileSystemWatcher fs1 = new FileSystemWatcher(@"c:\files", "file1");
if (!fs1.WaitForChanged(System.IO.WatcherChangeTypes.All, 10000).TimedOut) {
System.Console.WriteLine("f1 found!");
} else {
System.Console.WriteLine("f1 not found!");
}
}
static void t2() {
System.IO.FileSystemWatcher fs2 = new
System.IO.FileSystemWatcher(@"c:\files", "file2");
if (!fs2.WaitForChanged(System.IO.WatcherChangeTypes.All, 10000).TimedOut) {
System.Console.WriteLine("f2 found!");
} else {
System.Console.WriteLine("f2 not found!");
}
}
}
When copying file1 and file2 to the path c:\files (which are monitored by
the two FileSystemWatchers) only one of them receives a signal, the other one
simply timesout.
Please advice,
Best Regards,
Fredrik Johansson
I have built a .NET remoting solution (SingleCall) that writes a file to
disk, then waits for a second file in a specified folder (using the
FileSystemWatcher.WaitForChanged method). When the component is called by two
peers at the same time, two FileSystemWatchers are created (one for each
peer). They are both monitoring the same path (but for different files -
using different filters). The following code illustrates the scenario:
using System;
using System.IO;
using System.Threading;
class clsMain {
static void Main() {
Thread thread1 = new Thread(new ThreadStart(t1));
Thread thread2 = new Thread(new ThreadStart(t2));
thread1.Start();
thread2.Start();
Console.ReadLine();
}
static void t1() {
FileSystemWatcher fs1 = new FileSystemWatcher(@"c:\files", "file1");
if (!fs1.WaitForChanged(System.IO.WatcherChangeTypes.All, 10000).TimedOut) {
System.Console.WriteLine("f1 found!");
} else {
System.Console.WriteLine("f1 not found!");
}
}
static void t2() {
System.IO.FileSystemWatcher fs2 = new
System.IO.FileSystemWatcher(@"c:\files", "file2");
if (!fs2.WaitForChanged(System.IO.WatcherChangeTypes.All, 10000).TimedOut) {
System.Console.WriteLine("f2 found!");
} else {
System.Console.WriteLine("f2 not found!");
}
}
}
When copying file1 and file2 to the path c:\files (which are monitored by
the two FileSystemWatchers) only one of them receives a signal, the other one
simply timesout.
Please advice,
Best Regards,
Fredrik Johansson