BlobStorage.Advanced.DeleteContainersWithPrefixAsync C# (CSharp) Method

DeleteContainersWithPrefixAsync() private static method

Deletes containers starting with specified prefix. Note that the ListContainers method is called synchronously, for the purposes of the sample. However, in a real-world application using the async/await pattern, best practices recommend using asynchronous methods consistently.
private static DeleteContainersWithPrefixAsync ( Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient, string prefix ) : System.Threading.Tasks.Task
blobClient Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient The Blob service client.
prefix string The container name prefix.
return System.Threading.Tasks.Task
        private static async Task DeleteContainersWithPrefixAsync(CloudBlobClient blobClient, string prefix)
        {
            Console.WriteLine("Delete all containers beginning with the specified prefix");
            try
            {
                foreach (var container in blobClient.ListContainers(prefix))
                {
                    Console.WriteLine("\tContainer:" + container.Name);
                    if (container.Properties.LeaseState == LeaseState.Leased)
                    {
                        await container.BreakLeaseAsync(null);
                    }

                    await container.DeleteAsync();
                }

                Console.WriteLine();
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }