执行DownloadToFIleParallelAsync方法时出现问题

时间:2018-08-30 09:38:48

标签: azure azure-storage-blobs

我正在尝试使用DownloadToFIleParallelAsync方法将天蓝色的blob下载到本地文件中,以减少下载所需的时间。但是当该行执行时,我的程序执行继续保持。该行之后没有任何语句正在执行。这是我编写的代码。

    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Threading;
    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Blob;
    namespace demoAzure {     
    class Program     
    {         
    static void Main(string[] args)        
     {            
     var watch = System.Diagnostics.Stopwatch.StartNew();             Console.WriteLine("Downloading...");             ProcessBlob().GetAwaiter().GetResult();                         
    watch.Stop();            
    Console.WriteLine( "Execution Time: " + watch.ElapsedMilliseconds + " Milliseconds");           
     Console.ReadLine();         
    }         

    private static async Task ProcessBlob()        
     {             
    string storageconnectionstring = Environment.GetEnvironmentVariable("storageconnectionstring");             CloudStorageAccount storageAccount = null;             
    CloudBlobContainer container = null;              
    string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);             string blobName = "large rfa_15mb.RFA";             
    string downloadFilePath = Path.Combine(folderPath, blobName);              
    if (CloudStorageAccount.TryParse(storageconnectionstring, out storageAccount))             {                
     try                
     {                     
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();                     container = blobClient.GetContainerReference("blobcontainer");                     await container.CreateIfNotExistsAsync();                      
    CloudBlockBlob blob = container.GetBlockBlobReference(blobName);                                          //await blob.DownloadToFileAsync(downloadFilePath, FileMode.Create); 
await blob.DownloadToFileParallelAsync(downloadFilePath, FileMode.Create, 2, 4 * 1024 * 1024);                     
// blob.DownloadToFile(downloadFilePath, FileMode.Create);                                         Console.WriteLine("completed");    
                 }                
     catch (Exception ex)                
     {                    
     Console.WriteLine(ex.Message); 

     }             
    }            
     else            
     {                
     Console.WriteLine("No system environment variables are available. please set one");            
     }       
      }            
      } } 

0 个答案:

没有答案