public ViewModel(WidgetId id) : base(id) { Settings = id.GetSettings() as Settings; if (Settings == null) return; IsPaused = Settings.Freeze; ImageUrl = Settings.ImageUrl; AllowDrop = Settings.AllowDropFiles; TogglePlayPause = new RelayCommand(TogglePlayPauseExecute); _random = new Random(); _changeTimer = new DispatcherTimer {Interval = Settings.ChangeInterval}; _changeTimer.Tick += (sender, args) => NextImage(); _directoryWatcher = new DirectoryWatcher(new DirectoryWatcherSettings { WatchFolders = new List<string> {Settings.RootPath}, FileExtensionWhitelist = ImageHelper.SupportedExtensions, MaxSize = Settings.FileFilterSize, Recursive = Settings.Recursive, DetectNewFiles = false, DetectModifiedFiles = false }); _directoryWatcher.CheckDirectoriesForNewFiles(); NextImage(); if (Settings.Recursive) _directoryWatcher.CheckDirectoriesForNewFilesAsync(); _changeTimer.Start(); }
public override void OnClose() { base.OnClose(); _directoryWatcher?.Stop(); _directoryWatcher = null; _changeTimer?.Stop(); _changeTimer = null; }