Created
June 10, 2013 09:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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