取消上传任务

时间:2017-04-11 15:03:09

标签: c++ azure-storage-blobs casablanca cpprest-sdk

我已经完成了有关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附加到任务中。

任何指针?

1 个答案:

答案 0 :(得分:2)

a sample code using PPL library,我提到它并使用C ++ REST SDK中的PPLX库更改了取消任务的代码,该库用于Azure Storage SDK for 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();

希望它有所帮助。