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

Directory/File Copy/Move Cancel Support #30

Open
vector-man opened this issue Jun 26, 2021 · 4 comments
Open

Directory/File Copy/Move Cancel Support #30

vector-man opened this issue Jun 26, 2021 · 4 comments

Comments

@vector-man
Copy link

vector-man commented Jun 26, 2021

Can we get versions of all of the methods with cancellation support (cancellation tokens or something similar)? So that I can cancel a file or directory move/copy in progress?

@vector-man vector-man changed the title Async Methods Directory/File Copy/Move Cancel Support Jun 26, 2021
@hangy
Copy link

hangy commented Jun 27, 2021

The implementation here is just a wrapper around File.Copy, which does not have a cancellable implementation.

File.Copy(sourceFileName, path, overwrite);
I believe this is true for most operations. Implementing this depends on dotnet/runtime#20695 (comment).

@chinhdo
Copy link
Owner

chinhdo commented Jun 29, 2021

@hangy Thanks for the info. I think once cancelable support is available in .NET framework, we can work on adding it to this package.

@vector-man
Copy link
Author

vector-man commented Jun 30, 2021

Do you think doing it with FileStream.CopyToAsync(....) would work for now? I believe it's not as efficient as doing it with File.Copy(...), but it works.

More on the discussion of it's efficiency: https://stackoverflow.com/questions/882686/non-blocking-file-copy-in-c-sharp

@hangy
Copy link

hangy commented Jun 30, 2021

Do you think doing it with FileStream.CopyToAsync(....) would work for now? I believe it's not as efficient as doing it with File.Copy(...), but it works.

More on the discussion of it's efficiency: https://stackoverflow.com/questions/882686/non-blocking-file-copy-in-c-sharp

If all you care about is the file content, then you can use CopyToAsync. I believe either of the suggestions on SO will be fine.

But beware that File.Copy may work different than that, because it probably calls native file system functions. Those may also copy additional metadata like timestamps or ie. NTFS Alternate Streams, which copying the file stream won't do.

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

3 participants