Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If register the UpdateProgress event of ShellFileOperations, the operation will be invalid #146

Closed
zhuxb711 opened this issue Jul 12, 2020 · 5 comments

Comments

@zhuxb711
Copy link
Contributor

Describe the bug
If there is no following line, the operation is performed normally

 Operation.UpdateProgress += Progress;

If I register for the UpdateProgress event, the copy operation will be invalid. It means that no files are copied.

By the way, I want to know whether it is correct way to get the copy progress?

What code is involved

        public static bool Copy(IEnumerable<string> Source, string DestinationPath, ProgressChangedEventHandler Progress)
        {
            try
            {
                if (!Directory.Exists(DestinationPath))
                {
                    _ = Directory.CreateDirectory(DestinationPath);
                }

                using (ShellFileOperations Operation = new ShellFileOperations
                {
                    Options = ShellFileOperations.OperationFlags.AddUndoRecord | ShellFileOperations.OperationFlags.NoConfirmMkDir | ShellFileOperations.OperationFlags.Silent
                })
                {
                    Operation.UpdateProgress += Progress;

                    foreach (string SourcePath in Source)
                    {
                        using (ShellItem SourceItem = new ShellItem(SourcePath))
                        using (ShellFolder DestItem = new ShellFolder(DestinationPath))
                        {
                            Operation.QueueCopyOperation(SourceItem, DestItem);
                        }
                    }

                    Operation.PerformOperations();
                }

                return true;
            }
            catch
            {
                return false;
            }
        }

Expected behavior
Copy files and report progress

@dahall
Copy link
Owner

dahall commented Jul 12, 2020

This is the correct way. There was a bug which is now fixed that threw an exception thus causing the operation to not complete.

@dahall dahall closed this as completed Jul 12, 2020
@zhuxb711
Copy link
Contributor Author

When will a new version with this fix be released? Looking forward to your release.

@dahall
Copy link
Owner

dahall commented Jul 13, 2020

In the next 2-3 days.

@dahall
Copy link
Owner

dahall commented Jul 13, 2020

I have just released v3.2.12 with this fix

@zhuxb711
Copy link
Contributor Author

Got it, now it work well, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants