/// <summary> /// Method runs current copy process using BackGroundWorker async method /// </summary> /// <param name="pathToFile"></param> /// <param name="pathDirection"></param> public void StartCopy(string pathToFile, string pathDirection) { try { PathesToCopy pathes = new PathesToCopy { File = pathToFile, Directory = pathDirection }; ListSettings[ListSettings.Count - 1].BackgroundWorker.RunWorkerAsync(pathes); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Method runs copy process /// </summary> /// <param name="sender"></param> /// <param name="doWorkEventArgs"></param> private void BackgroundWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs) { try { PathesToCopy pathes = (PathesToCopy)doWorkEventArgs.Argument; FileOperator.CopyFile(pathes.File, pathes.Directory, BackgroundWorker, _eventBusy); if (BackgroundWorker.CancellationPending) { doWorkEventArgs.Cancel = true; return; } doWorkEventArgs.Result = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }