Closed JgBr123 closed 1 month ago
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");
}
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.