注意:回答我自己的问题,以便将来帮助其他人。
我正在关注 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"];
我如何让它工作?
最佳答案
这个问题在这里有解决方案https://github.com/aws/aws-sdk-net/issues/152
我的问题是我从 WinForm 应用程序运行这个示例。
Winform 应用程序 Main()
方法标有单线程单元属性 [STAThread]
。这会导致异步失败。
要么删除 [STAThread]
属性,要么创建另一个没有它的 Main()
方法。
关于c# - AWS S3 GetObjectAsync 挂起/超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50920575/