我的ms bot框架中有:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
context.Wait(MessageReceivedAsync);
}
如何设置等待时间await result
?
答案 0 :(得分:3)
我建议您尝试以下操作:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
// Set the delay to whatever timeout interval you need (in milliseconds)
if (Task.WaitAny(result.ToTask(), Task.Delay(1000)) == result)
{
var activity = await result as Activity;
}
else
{
// Didn't complete during the defined interval
}
context.Wait(MessageReceivedAsync);
}
更新
添加了ToTask()用法,可将IAwaitable
转换为Task
可以使用的WhenAny
。
希望有帮助!