我试图使用Microsoft.Azure.Storage.DataMovement包从UI上传Blob文件到Azure,但一直遇到死锁,我需要等待上传完成才能删除文件。我按照DataMovement站点上的示例代码进行操作,但是当我发出task.Wait()时,它会阻止该线程,我不能在生活中解决如何在UI中执行此操作。
// Setup the number of the concurrent operations
TransferManager.Configurations.ParallelOperations = 64;
// Setup the transfer context and track the upoload progress
SingleTransferContext context = new SingleTransferContext();
context.ProgressHandler = new Progress<TransferStatus>((progress) =>
{
if (progressHandler != null)
{
int percentUploaded = (int)(progress.BytesTransferred / new FileInfo(creationArgs.SnapshotFileName).Length);
progressHandler.Report(percentUploaded);
}
});
// Upload a local blob
var task = TransferManager.UploadAsync(
sourcePath, destBlob, null, context, CancellationToken.None);
task.Wait();