我想使用以下方法将 AWS S3 异步方法转换为任务:
using (var client = AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey))
{
var request = new PutObjectRequest();
// ... set request properties ...
await Task.Factory.FromAsync<PutObjectRequest, PutObjectResponse>(
client.BeginPutObject,
client.EndPutObject,
request,
null
);
}
但是,我得到以下异常:
System.ArgumentException: The IAsyncResult object was not returned from the corresponding asynchronous method on this class.
Parameter name: asyncResult
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Amazon.S3.AmazonS3Client.getResponseCallback[T](IAsyncResult result)
at Amazon.S3.AmazonS3Client.endOperation[T](IAsyncResult result)
at Amazon.S3.AmazonS3Client.EndPutObject(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
我的电话是FromAsync
不正确的还是这里出了什么问题?
附言
- .NET 框架 4.5
- AWSSDK 版本 1.5.17.0