class Program {
static void Main(string[] args) {
}
private Assembly ApplicationAssembly {
get;
set;
}
private FileSystemWatcher appUpdateWatcher;
private EventHandler applicationUpdated;
public event EventHandler ApplicationUpdated {
add {
applicationUpdated = (EventHandler)Delegate.Combine(applicationUpdated, value);
UpdateAppUpdateWatcher();
}
remove {
applicationUpdated = (EventHandler)Delegate.Remove(applicationUpdated, value);
}
}
private void UpdateAppUpdateWatcher() {
if(applicationUpdated != null && appUpdateWatcher == null && ApplicationAssembly != null) {
appUpdateWatcher = new FileSystemWatcher(Path.GetDirectoryName(ApplicationAssembly.Location), "*.exe");
appUpdateWatcher.Renamed += (o, args) => {
var handler = applicationUpdated;
if(handler != null)
handler(this, EventArgs.Empty);
};
}
}
}