public void ChangePath(string newPath, string newExtension) { lock (Incubator) { if (DiscoveryThread != null && DiscoveryThread.IsBusy) { DiscoveryThread.RunWorkerCompleted += (sender, args) => { ShouldAbort = false; FolderPath = newPath; FileExtension = newExtension; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); MainWindow.Options.Movies.Clear(); MainWindow.Options.DisplayedMovie = null; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); }; ShouldAbort = true; } else { FolderPath = newPath; FileExtension = newExtension; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); MainWindow.Options.Movies.Clear(); MainWindow.Options.DisplayedMovie = null; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); } } }
private void ButtonChangeFolder_OnClick(object sender, RoutedEventArgs e) { System.Windows.Forms.FolderBrowserDialog Dialog = new System.Windows.Forms.FolderBrowserDialog(); System.Windows.Forms.DialogResult Result = Dialog.ShowDialog(); if (Result.ToString() == "OK") { if (!IOHelper.CheckFolderPermission(Dialog.SelectedPath)) { MessageBox.Show("Don't have permission to access the selected folder."); return; } if (Dialog.SelectedPath.Last() != '\\') { Dialog.SelectedPath += '\\'; } ButtonChangeFolder.Content = Dialog.SelectedPath; ButtonCreate.Visibility = Visibility.Visible; } }
public void ChangePath(string newPath, string newExtension) { IncubationEnded?.Invoke(); lock (Incubator) { if (DiscoveryThread != null && DiscoveryThread.IsBusy) { DiscoveryThread.RunWorkerCompleted += (sender, args) => { FileWatcher.EnableRaisingEvents = false; FileWatcherRaised = false; ShouldAbort = false; FolderPath = newPath; FileExtension = newExtension; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); }; ShouldAbort = true; } else { FolderPath = newPath; FileExtension = newExtension; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); } } }
public void ChangePath(string newPath) { IncubationEnded?.Invoke(); lock (Incubator) { if (DiscoveryThread != null && DiscoveryThread.IsBusy) { DiscoveryThread.RunWorkerCompleted += (sender, args) => { FileWatcher.EnableRaisingEvents = false; FileWatcherRaised = false; ShouldAbort = false; FolderPath = newPath; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Task.WaitAll(CreationTasks.Values.ToArray()); //Thread.Sleep(500); // There might still be item creation tasks running asynchro Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); }; ShouldAbort = true; } else { FolderPath = newPath; if (FolderPath == "" || !Directory.Exists(FolderPath) || !IOHelper.CheckFolderPermission(FolderPath)) { return; } Incubator.Clear(); lock (Ripe) Ripe.Clear(); FilesChanged?.Invoke(); FileWatcher.Path = FolderPath; FileWatcher.Filter = FileExtension; FileWatcher.EnableRaisingEvents = true; DiscoveryThread = new BackgroundWorker(); DiscoveryThread.DoWork += WorkLoop; DiscoveryThread.RunWorkerAsync(); } } }