A
Antoine Drochon
Hi,
I would like to watch on 3 differents files (containing web-application
specific configuration). To do this, i wrote the following code in the
Application_Start of my Global class.
--------8<----------------------------------------8<-------
[C#]
terminalWatcher = new FileSystemWatcher();
sfparamsWatcher = new FileSystemWatcher();
siteconfigWatcher = new FileSystemWatcher();
terminalWatcher.Path = ConfigurationSettings.AppSettings["RessourcePath"];
terminalWatcher.Filter = "terms.xml";
terminalWatcher.Changed += new FileSystemEventHandler(terminalChanged);
terminalWatcher.Created += new FileSystemEventHandler(terminalChanged);
terminalWatcher.Deleted += new FileSystemEventHandler(terminalChanged);
terminalWatcher.EnableRaisingEvents = true;
sfparamsWatcher.Path = ConfigurationSettings.AppSettings["RessourcePath"];
sfparamsWatcher.Filter = "sfparams.xml";
sfparamsWatcher.Changed += new FileSystemEventHandler(sfparamsChanged);
sfparamsWatcher.Created += new FileSystemEventHandler(sfparamsChanged);
sfparamsWatcher.Deleted += new FileSystemEventHandler(sfparamsChanged);
sfparamsWatcher.EnableRaisingEvents = true;
siteconfigWatcher.Path = ConfigurationSettings.AppSettings["RessourcePath"];
siteconfigWatcher.Filter = "sites.xml";
siteconfigWatcher.Changed += new FileSystemEventHandler(siteconfigChanged);
siteconfigWatcher.Created += new FileSystemEventHandler(siteconfigChanged);
siteconfigWatcher.Deleted += new FileSystemEventHandler(siteconfigChanged);
siteconfigWatcher.EnableRaisingEvents = true;
[...]
private static void terminalChanged(
object source, FileSystemEventArgs e)
{
Terminal.ResetTerminal();
return;
}
private static void sfparamsChanged(
object source, FileSystemEventArgs e)
{
// Read the SFParams.xml
ParamCollection.GetCurrent();
}
private static void siteconfigChanged(
object source, FileSystemEventArgs e)
{
// Read the Sites.xml
SiteList.GetCurrent();
}
--------8<----------------------------------------8<-------
But only the first Watcher seems to work. I think this is a threading
issue when entering in the Changed' methods. How to make this 3
FileSystemWatcher work ?
Thank you for your help,
Antoine D.
I would like to watch on 3 differents files (containing web-application
specific configuration). To do this, i wrote the following code in the
Application_Start of my Global class.
--------8<----------------------------------------8<-------
[C#]
terminalWatcher = new FileSystemWatcher();
sfparamsWatcher = new FileSystemWatcher();
siteconfigWatcher = new FileSystemWatcher();
terminalWatcher.Path = ConfigurationSettings.AppSettings["RessourcePath"];
terminalWatcher.Filter = "terms.xml";
terminalWatcher.Changed += new FileSystemEventHandler(terminalChanged);
terminalWatcher.Created += new FileSystemEventHandler(terminalChanged);
terminalWatcher.Deleted += new FileSystemEventHandler(terminalChanged);
terminalWatcher.EnableRaisingEvents = true;
sfparamsWatcher.Path = ConfigurationSettings.AppSettings["RessourcePath"];
sfparamsWatcher.Filter = "sfparams.xml";
sfparamsWatcher.Changed += new FileSystemEventHandler(sfparamsChanged);
sfparamsWatcher.Created += new FileSystemEventHandler(sfparamsChanged);
sfparamsWatcher.Deleted += new FileSystemEventHandler(sfparamsChanged);
sfparamsWatcher.EnableRaisingEvents = true;
siteconfigWatcher.Path = ConfigurationSettings.AppSettings["RessourcePath"];
siteconfigWatcher.Filter = "sites.xml";
siteconfigWatcher.Changed += new FileSystemEventHandler(siteconfigChanged);
siteconfigWatcher.Created += new FileSystemEventHandler(siteconfigChanged);
siteconfigWatcher.Deleted += new FileSystemEventHandler(siteconfigChanged);
siteconfigWatcher.EnableRaisingEvents = true;
[...]
private static void terminalChanged(
object source, FileSystemEventArgs e)
{
Terminal.ResetTerminal();
return;
}
private static void sfparamsChanged(
object source, FileSystemEventArgs e)
{
// Read the SFParams.xml
ParamCollection.GetCurrent();
}
private static void siteconfigChanged(
object source, FileSystemEventArgs e)
{
// Read the Sites.xml
SiteList.GetCurrent();
}
--------8<----------------------------------------8<-------
But only the first Watcher seems to work. I think this is a threading
issue when entering in the Changed' methods. How to make this 3
FileSystemWatcher work ?
Thank you for your help,
Antoine D.