AWS S3 GetObjectAsync挂起/超时

问题描述 投票:2回答:1

注意:回答我自己的问题以帮助其他人。

我正在关注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"];

我如何让它工作?

c# amazon-web-services amazon-s3 async-await hang
1个回答
1
投票

这个问题在这里有解决方案https://github.com/aws/aws-sdk-net/issues/152

对我来说问题是我从WinForm应用程序运行此示例。

Winform apps Main()方法标有Single Threaded Apartment属性[STAThread]。这会导致Async失败。

要么删除[STAThread]属性,要么在没有它的情况下制作另一个Main()方法。

© www.soinside.com 2019 - 2024. All rights reserved.