public async void CopyFiles(FileInfo copyfile, ListView destinationListView)
        {
            cts = new CancellationTokenSource();
            pts = new PauseTokenSource();

            if (destinationListView.SelectedValue != null)
            {
                var destinationPath     = (destinationListView.SelectedValue as DirectoryInfo).FullName;
                var fullDestinationPath = destinationPath + "\\copy_" + copyfile.Name;
                var dictionary          = new Dictionary <string, string> {
                    { copyfile.FullName, fullDestinationPath }
                };
                progressBar.Maximum = 10000.0;

                try
                {
                    await Copier.CopyFiles(dictionary, cts.Token, pts.Token, prog => progressBar.Value = prog);
                }
                catch (OperationCanceledException exception)
                {
                    File.Delete(fullDestinationPath);
                }

                Close();
            }
            else
            {
                var destinationPath     = "D:";
                var fullDestinationPath = destinationPath + "\\copy_" + copyfile.Name;

                var dictionary = new Dictionary <string, string>
                {
                    { copyfile.FullName, fullDestinationPath }
                };

                progressBar.Maximum = 10000.0;

                try
                {
                    await Copier.CopyFiles(dictionary, cts.Token, pts.Token, prog => progressBar.Value = prog);
                }
                catch (OperationCanceledException exception)
                {
                    File.Delete(fullDestinationPath);
                }

                Close();
            }
        }
Example #2
0
 internal PauseToken(PauseTokenSource source)
 {
     m_source = source;
 }