本文介绍了如何等待方法从Azure Blob存储中完成下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在从Azure Blob存储&中下载一些blobitem我的代码是

Hi,

I am downloading some blobitem from Azure Blob Storage & my code is

public Response DownloadFilesFromAzure(List<string> fileNameList, string folderPath)
{
	response = new Response();
	try
	{
		string azureConnectionStrig = "DefaultEndpointsProtocol=https;AccountName=" + storageConfig.AccountName + ";AccountKey=" + storageConfig.AccesssKey;
		storageAcc = CloudStorageAccount.Parse(azureConnectionStrig);
		blobClient = storageAcc.CreateCloudBlobClient();
		container = blobClient.GetContainerReference(storageConfig.AccountName); // BlobName : storageConfig.AccountName           

		foreach (var blobitem in fileNameList)
		{
			var blobItems = container.ListBlobs(blobitem).ToList();

			blockBlob = container.GetBlockBlobReference(blobItems[0].Uri.ToString());
			var fileName = blockBlob.Name.Substring(blockBlob.Name.LastIndexOf('/') + 1);

			blockBlob.BeginDownloadToFile(Path.Combine(folderPath, fileName), FileMode.OpenOrCreate, null, null);

			//Task task = Task.Run(()=> blockBlob.BeginDownloadToFile(Path.Combine(folderPath, fileName), FileMode.OpenOrCreate, null, null));
			//task.Wait();                    
		}

		// here my method to zip & move file
		ZipAndMove();

		response.ErrorCode = ErrorCode.Success;
		return response;

	}
	catch (Exception e)
	{
		Logging.Log(e.Message, 20, true);
		throw e;
	}
}





问题是在下载完成之前调用ZipAndMove的方法。

我也使用注释代码,即



the Problem is method ZipAndMove is called before download complete.
I also use the commented code i.e

//Task task = Task.Run(()=> blockBlob.BeginDownloadToFile(Path.Combine(folderPath, fileName), FileMode.OpenOrCreate, null, null));
//task.Wait();





但问题仍然存在。



请帮助解决这个问题。



but the problem remain.

Please help to solve this problem.

推荐答案


这篇关于如何等待方法从Azure Blob存储中完成下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:04