取消上传任务

Cancelling an upload task

本文关键字:任务 取消      更新时间:2023-10-16

我已经阅读了一些关于Azure SDK的阅读,为了取消一个任务,你似乎需要传递一个cancellation_token

我的上传代码非常简单:

azure::storage::cloud_block_blob blockBlob = container.get_block_blob_reference(fileLeaf.wstring());
auto task = blockBlob.upload_from_file_async(fullFilePath);

但是,我上传的某些文件可能非常大,我希望能够取消此操作。 如果可能的话,我可能还会使用延续,并且也需要所有这些取消。

遇到的问题是我看不到任何将cancellation_token附加到任务的方法。

有什么指示吗?

有一个

使用 PPL 库的示例代码,我参考了它并更改了使用 REST SDK 中的 PPLX 库取消任务的代码C++该代码用于 Azure 存储 SDK,用于C++,请尝试以下代码。

/* Declare a cancellation_token_source and get the cancellation_token, 
 * please see http://microsoft.github.io/cpprestsdk/classpplx_1_1cancellation__token__source.html
*/
#include <pplxtasks.h>
cancellation_token_source cts;
auto token = cts.get_token();
//Pass the cancellation_toke to task via then method, please see https://msdn.microsoft.com/en-us/library/jj987787.aspx
task.then([]{}, token).wait();
// Cancel the task
cts.cancel();

希望对您有所帮助。