當前位置: 首頁>>代碼示例>>C#>>正文


C# CloudQueueClient.ListQueuesSegmentedAsync方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient.ListQueuesSegmentedAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudQueueClient.ListQueuesSegmentedAsync方法的具體用法?C# CloudQueueClient.ListQueuesSegmentedAsync怎麽用?C# CloudQueueClient.ListQueuesSegmentedAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient的用法示例。


在下文中一共展示了CloudQueueClient.ListQueuesSegmentedAsync方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ListQueuesSample

        /// <summary>
        /// Create, list and delete queues
        /// </summary>
        /// <param name="cloudQueueClient"></param>
        /// <returns></returns>
        private static async Task ListQueuesSample(CloudQueueClient cloudQueueClient)
        {
            // Create 3 queues.

            // Create the queue name -- use a guid in the name so it's unique.
            string baseQueueName = "demotest-" + System.Guid.NewGuid().ToString();

            // Keep a list of the queues so you can compare this list 
            //   against the list of queues that we retrieve.
            List<string> queueNames = new List<string>();

            for (int i = 0; i < 3; i++)
            {
                // Set the name of the queue, then add it to the generic list.
                string queueName = baseQueueName + "-0" + i;
                queueNames.Add(queueName);

                // Create the queue with this name.
                Console.WriteLine("Creating queue with name {0}", queueName);
                CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(queueName);
                try
                {
                    await cloudQueue.CreateIfNotExistsAsync();
                    Console.WriteLine("    Queue created successfully.");
                }
                catch (StorageException exStorage)
                {
                    Common.WriteException(exStorage);
                    Console.WriteLine(
                        "Please make sure your storage account is specified correctly in the app.config - then restart the sample.");
                    Console.WriteLine("Press any key to exit");
                    Console.ReadLine();
                    throw;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("    Exception thrown creating queue.");
                    Common.WriteException(ex);
                    throw;
                }
            }

            Console.WriteLine(string.Empty);
            Console.WriteLine("List of queues in the storage account:");

            // List the queues for this storage account 
            QueueContinuationToken token = null;
            List<CloudQueue> cloudQueueList = new List<CloudQueue>();

            do
            {
                QueueResultSegment segment = await cloudQueueClient.ListQueuesSegmentedAsync(baseQueueName, token);
                token = segment.ContinuationToken;
                cloudQueueList.AddRange(segment.Results);
            }
            while (token != null);

            try
            {
                foreach (CloudQueue cloudQ in cloudQueueList)
                {
                    Console.WriteLine("Cloud Queue name = {0}", cloudQ.Name);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("    Exception thrown listing queues.");
                Common.WriteException(ex);
                throw;
            }

            // Now clean up after yourself, using the list of queues that you created in case there were other queues in the account.
            foreach (string oneQueueName in queueNames)
            {
                CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(oneQueueName);
                cloudQueue.DeleteIfExists();
            }
        }
開發者ID:Azure-Samples,項目名稱:storage-queue-dotnet-getting-started,代碼行數:83,代碼來源:Advanced.cs


注:本文中的Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient.ListQueuesSegmentedAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。