my application read DLL data from cache. but if any developer change DLLs DllCaching must change. So i have been using FileSystemWatcher to detect any changes on DLLs .
My systen Watcher mechanizm below: this project is in asp.net
public void CreateFileWatcher(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.IncludeSubdirectories = true;
watcher.Filter = "*.dll";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnChanged);
// Begin watching.
watcher.EnableRaisingEvents = true;
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
//FillCache
}
Button1_Click
{
CreateFileWatcher(@"C:/data")
// like that:
myarray = CachData
}
How to make it? how to load dll(again loading) when Dlls changes.
It is a hurdle on how to clear cache if you are using cache in your application and it becomes tough when you implement a custom logic to clear cache. If you are using EnterpriseLibrary cache, we can have a dependency while adding items to the cache. Any change to this file will clear the cache.
Below is the sample code. The same overload is available for asp.net cache as well.