wp8.1获得blob异步上传文件完成之后的提示

HELLO!!大家好!!
我是在windows phone8.1中

blockBlob.UploadFromFileAsync(file);

我想在文件上传成功之后执行一个方法或者一些操作,同时不想阻塞主线程。

我看到了文件操作完成后有一个IAsyncAction.Completed,但是并不会用orz,

希望得到指点,一些实例代码就可以帮助我了,
谢谢!!

您好,

据我的经验来看,您在执行UploadFromFileAsync()这个函数之前,是您上传文件之前的逻辑处理,在这个函数之后则是文件上传完毕之后处理。由于这个函数自身就是异步方法,他是不会阻塞您的主线程的。 你也可以尝试下我下面的这个方法:

 private async void UploadFile(StorageFile file)
 {
 string accountName = "<Storage Name Here>";
 string accountKey = "<Storage Key Here>";

 try
 {
 StorageCredentials creds = new StorageCredentials(accountName, accountKey);
 CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
 CloudBlobClient client = account.CreateCloudBlobClient();
 CloudBlobContainer sampleContainer = client.GetContainerReference("<Container Name Here>");
 sampleContainer.CreateIfNotExistsAsync(); 

 CloudBlockBlob blob = sampleContainer.GetBlockBlobReference(file.Name);

 //Before uploading, set the your handler function


 await blob.UploadFromFileAsync(file);

 //After uploading is complete,  run  your handler function

 //Preview the image by pointing to the Uri of the container
 ImageSource imgSource = new BitmapImage(blob.Uri);
 Image1.Source = imgSource;
 }
 catch (Exception ex)
 {
 //*****
 }
 }

与此同时,如果您想精准的控制您的文件上传过程,我推荐您参考下Kevin William的这篇blog:

http://blogs.msdn.com/b/kwill/archive/2011/05/30/asynchronous-parallel-block-blob-transfers-with-progress-change-notification.aspx

Regards,

Will
如果您想进一步了解Windows Azure, Windows Azure 官网欢迎您的访问