2017-04-11 208 views
2

我已经做了一些关于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附加到任务。

任何指针?

回答

2

还有a sample code using PPL library,我提到它,并在用于C++的Azure存储SDK中使用C++ REST SDK中的PPLX库更改了取消任务的代码,请尝试下面的代码。

/* 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(); 

希望它有帮助。

+0

非常感谢 - 将取消标记传递给'then'是我所缺少的,我最终通过'create_if_not_exists_async'创建了一个任务,然后在其中添加了一个带有取消标记的任务。 –