Jan*_*nak 7 c# azure azure-storage azure-storage-blobs
在我的应用程序中,我想要我的容器的所有blob但在我的代码中(如下所示)在CloudBlobContainer变量容器中没有Listblob()方法.我错过了什么吗?
var credentials = new StorageCredentials("xxx", "a37bijfRGGdgaVU+ITEIi0Cp1VrbzMM7Bc9PbMOw2FPAz9twgR+lbTzqGhBfHeJe7UfEp4CXtLxqY5Ek0/5zdg==");
var client = new CloudBlobClient(new Uri("https://xxx.blob.core.windows.net/"), credentials);
var container = client.GetContainerReference("publicimage");
//this container variable has not ListBlobs() method
foreach(IListBlobItem item in container.ListBlobsSegmentedAsync())
{
}
Run Code Online (Sandbox Code Playgroud)
Ser*_*ler 10
ListBlobs是一种同步方法,因此在不支持Windows Phone等同步方法的平台上缺失.原因是在UI线程上调用同步方法会阻止UI并使应用程序无响应.
另一种方法是使用*Async重载.但请注意,没有ListBlobsAsync,因为.NET中没有IEnumerable的异步对应物.因此,您应该调用ListBlobsSegmentedAsync并处理它返回的延续令牌.
如果您希望查看示例用法,我建议您查看Azure存储客户端库的单元测试(请参阅CloudBlobContainerTest.cs中的测试CloudBlobContainerListBlobsSegmentedAsync).