private void btnCopy_Click(object sender, EventArgs e) { if (cboSrouce.SelectedItem == null) { MessageBox.Show("Please select a source", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var sources = new SourceFilesBuilder(cboSrouce.SelectedItem.ToString()); var destinations = new List<DestinationLocationBuilder>(); if (!string.IsNullOrWhiteSpace(cboDest1.Text)) { destinations.Add(new DestinationLocationBuilder(cboDest1.Text, txtCopyTo.Text)); } if (!string.IsNullOrWhiteSpace(cboDest2.Text)) { destinations.Add(new DestinationLocationBuilder(cboDest2.Text, txtCopyTo.Text)); } var destination = new DestinationLocationBuilder(cboDest1.Text, txtCopyTo.Text); var destination2 = new DestinationLocationBuilder(cboDest2.Text, txtCopyTo.Text); this.btnCopy.Enabled = false; var copier = new FileCopyFacade(sources, destinations); progressBar1.Maximum = copier.FilesCount(); progressBar1.Step = 1; progressBar1.Value = 0; Thread thd_main = new Thread(copier.CopyAll); thd_main.Start(); Thread thread3 = new Thread(delegate (object x) { while (thd_main.IsAlive) { lock (this.locker) { Monitor.Wait(this.locker, TimeSpan.FromSeconds(2.0)); } } this.EnableBack(); }); lock (this.locker) { Monitor.Wait(this.locker, TimeSpan.FromSeconds(2.0)); } thread3.Start(); }
public FileCopyFacade(SourceFilesBuilder sourceFileBuilder, List<DestinationLocationBuilder> destinations) { _sourceFileBuilder = sourceFileBuilder; _destinationLocations = destinations; }