private void StartSort_Click(object sender, RoutedEventArgs e) { bool abort = false; if (!Directory.Exists(SourcePath.Text)) { MessageBox.Show("Choosen Source path does not exist."); abort = true; } if (!Directory.Exists(DestinationPath.Text)) { MessageBox.Show("Choosen Destination path does not exist."); abort = true; } if (abort) { return; } SorterInfomation sorterInfo = new SorterInfomation(SourcePath.Text, DestinationPath.Text); BackgroundWorker worker = new BackgroundWorker(); SortingWorker sortingWorker = new SortingWorker(); worker.WorkerReportsProgress = true; worker.DoWork += sortingWorker.worker_DoWork; worker.ProgressChanged += sortingWorker.worker_ProgressChanged; worker.RunWorkerCompleted += sortingWorker.worker_RunWorkerCompleted; worker.RunWorkerAsync(sorterInfo); }
private bool SpaceForWorker(int left, int right) { for (int i = 0; i < threadpool.Length; i++) { if (threadpool[i] == null) { SortingWorker worker = new SortingWorker(delegate() { ConcurrentQuickSort(left, right); }); threadpool[i] = new Thread(new ThreadStart(worker.Work)); threadpool[i].Start(); return(true); } } return(false); }