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

How to abort a file transfer in the middle? #270

Closed
JgBr123 opened this issue Jul 23, 2024 · 1 comment
Closed

How to abort a file transfer in the middle? #270

JgBr123 opened this issue Jul 23, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@JgBr123
Copy link

JgBr123 commented Jul 23, 2024

I see that it was mentioned before that a file transfer could be aborted by throwing an exception in the progressCallback. The problem is that i couldn't manage to do that, as the exception is not passed to the UploadFileAsync method, and instead is thrown into my main thread.

@wiz0u
Copy link
Owner

wiz0u commented Jul 24, 2024

yes, you also have to try..catch around your UploadFileAsync obviously

example with download:

var cts = new CancellationTokenSource(); // some other thread/task may trigger the cts.Cancel()
try
{
	using var fs = new FileStream("download.bin", FileMode.Create);
	await Client.DownloadFileAsync(document, fs, progress: (progress, total) => cts.Token.ThrowIfCancellationRequested());
}
catch (OperationCanceledException ex)
{
	Console.WriteLine("Transfer was aborted");
}

@wiz0u wiz0u closed this as completed Jul 24, 2024
Repository owner locked as too heated and limited conversation to collaborators Jul 24, 2024
Repository owner deleted a comment from JgBr123 Jul 27, 2024
Repository owner deleted a comment from JgBr123 Jul 27, 2024
@wiz0u wiz0u added the documentation Improvements or additions to documentation label Jul 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants