注意:回答我自己的问题,以便将来帮助其他人。
我跟随official documentation从S3存储桶中获取文本文件并挂起:
static async Task ReadObjectDataAsync()
{
string responseBody = "";
try
{
GetObjectRequest request = new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
};
//THIS NEXT LINE HANGS!!!!
using (GetObjectResponse response = await client.GetObjectAsync(request))
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
string title = response.Metadata["x-amz-meta-title"];
如何让它发挥作用?
答案 0 :(得分:1)
此问题的解决方案https://github.com/aws/aws-sdk-net/issues/152
问题在于我从WinForm应用程序运行此示例。
Winform apps Main()
方法标有Single Threaded Apartment属性[STAThread]
。这会导致Async失败。
删除[STAThread]
属性或不使用其他Main()
方法。