Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

c# - Calling async method results in WaitingForActivation “Not yet computed” error

I'm not sure why call to an async method yields no result. Below is my code, which makes call to same async function twice, however latter fails to to yield any result and results in

Id = 1, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

Code:

void async void FunctiontHandler(S3Event s3Event, ILambdaContext context)
{
    var dwnldKeybankFilePrefix = prefix + "KEYBANK_" + Function.outputZipFileSuffix + "/ST";
    var dwnldKeybankListTask = toEFS.ListDownloadObjectsAsync(bucket, dwnldKeybankFilePrefix, s3client);
              
    var dwnldKeybankList = await dwnldKeybankListTask;
                   
    var dwnldAOCFilePrefix = prefix + "AOC_" + Function.outputZipFileSuffix + "/" + AOCFilePrefix;

    //Here the method yields nothing and comes up with message as stated above
    var dwnldAOCListTask = toEFS.ListDownloadObjectsAsync(bucket, dwnldAOCFilePrefix, s3client);
    var dwnldAOCList = await dwnldKeybankListTask;     
    dwnldKeybankList.AddRange(dwnldAOCList);
}
question from:https://stackoverflow.com/questions/65869168/calling-async-method-results-in-waitingforactivation-not-yet-computed-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not really sure this is your problem,

however, you are awaiting await dwnldKeybankListTask twice, and not awaiting dwnldAOCListTask at all and passing the task straight to dwnldKeybankList

Try this

void async void FunctiontHandler(S3Event s3Event, ILambdaContext context)
{
    var bankPrefix = $"{prefix}KEYBANK_{Function.outputZipFileSuffix}/ST";

    var bankList = await  toEFS.ListDownloadObjectsAsync(bucket, bankPrefix , s3client);

    var aocPrefix = $"{prefix}AOC_{Function.outputZipFileSuffix}/{AOCFilePrefix}";

    var aocList = await toEFS.ListDownloadObjectsAsync(bucket, aocPrefix, s3client);

    bankList.AddRange(aocList);
}

Also you are using async void, 9 times out of 10 you will actually want async Task. Additionally your variables names are fairly confusing


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...