【发布时间】:2015-08-03 22:09:27
【问题描述】:
我正在制作一个小应用程序,它应该列出我的 Azure 队列中的项目数。 当我在控制台应用程序中使用 FetchAttributesAsync 和 ApproximateMessageCount 时,在调用 FetchAttributesAsync(或 FetchAttributes)后,我在 ApproximateMessageCount 中得到了预期的结果。
当我在通用 Windows 应用程序中使用它时,ApproximateMessageCount 在调用 FetchAttributesAsync 后仍然停留在 null(FetchAttributes 在那里不可用)。
控制台代码:
CloudStorageAccount _account;
if (CloudStorageAccount.TryParse(_connectionstring, out _account))
{
var queueClient = _account.CreateCloudQueueClient();
Console.WriteLine(" {0}", _account.QueueEndpoint);
Console.WriteLine(" ----------------------------------------------");
var queues = (await queueClient.ListQueuesSegmentedAsync(null)).Results;
foreach (CloudQueue q in queues)
{
await q.FetchAttributesAsync();
Console.WriteLine($" {q.Name,-40} {q.ApproximateMessageCount,5}");
}
}
通用应用代码:
IEnumerable<CloudQueue> queues;
CloudStorageAccount _account;
CloudQueueClient queueClient;
CloudStorageAccount.TryParse(connectionstring, out _account);
queueClient = _account.CreateCloudQueueClient();
queues = (await queueClient.ListQueuesSegmentedAsync(null)).Results;
foreach (CloudQueue q in queues)
{
await q.FetchAttributesAsync();
var count = q.ApproximateMessageCount;
// count is always null here!!!
}
我已经尝试了各种替代方法,例如 Wait() 等可等待对象。无论我尝试什么,ApproximateMessageCount 都会保持null 的决心:-(。
我错过了什么吗?
【问题讨论】:
标签: azure win-universal-app azure-queues