C# 使用HttpClient.PutAsync()批上载
我正在尝试使用HttpClient.PutAsync()将多个映像同时上载到Windows Azure存储。代码段如下所示:C# 使用HttpClient.PutAsync()批上载,c#,azure-storage,dotnet-httpclient,C#,Azure Storage,Dotnet Httpclient,我正在尝试使用HttpClient.PutAsync()将多个映像同时上载到Windows Azure存储。代码段如下所示: Task<HttpResponseMessage> putThumbnail = httpclient.PutAsync(new Uri(ThumbnailSas), thumbcontent); Task<HttpResponseMessage> putImage = httpclient.PutAsync(new Uri(ImageSas),
Task<HttpResponseMessage> putThumbnail = httpclient.PutAsync(new Uri(ThumbnailSas), thumbcontent);
Task<HttpResponseMessage> putImage = httpclient.PutAsync(new Uri(ImageSas), imagecontent);
Task.WaitAll(new Task<HttpResponseMessage>[] {putThumbnail, putImage});
如何使用HttpClient.PutAsync批量上传图像?您不应该阻止
async
code
在这种情况下,您可以使用任务。当所有:
Task<HttpResponseMessage> putThumbnail = ...;
Task<HttpResponseMessage> putImage = ...;
await Task.WhenAll(putThumbnail, putImage);
Task putThumbnail=。。。;
任务图像=。。。;
等待任务。WhenAll(putthumbail,putImage);
另请参见my或my结尾的图5。可能的重复-我相信PutAsync没有任何具体内容,而是您正在同步等待(WaitAll
)所有阻止完成PutAsync
调用的结果。这就是确切的答案。:)谢谢分享这个伟大的博客。
Task<HttpResponseMessage> putThumbnail = ...;
Task<HttpResponseMessage> putImage = ...;
await Task.WhenAll(putThumbnail, putImage);