Skip to content

Instantly share code, notes, and snippets.

@sebnilsson
Created June 10, 2013 09:12
Show Gist options
  • Save sebnilsson/5747448 to your computer and use it in GitHub Desktop.
Save sebnilsson/5747448 to your computer and use it in GitHub Desktop.
Disk-file dependency helper for restarting ASP.NET Environment on disk-file change
public static class DiskFileDependencyHelper
{
public static void AddRestartWatch(string filePath)
{
var fileInfo = new FileInfo(filePath);
if (fileInfo.Directory == null)
{
throw new FileNotFoundException("File or folder not found.", filePath);
}
var configWatcher = new FileSystemWatcher(fileInfo.Directory.FullName, fileInfo.Name);
configWatcher.Changed += ConfigWatcherChanged;
configWatcher.EnableRaisingEvents = true;
}
private static void ConfigWatcherChanged(object sender, FileSystemEventArgs e)
{
HttpRuntime.UnloadAppDomain();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment