0

I have in my ms bot framework:

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
    var activity = await result as Activity;
    context.Wait(MessageReceivedAsync);
}

How can I to set the wait time await result?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
M.Tony
  • 11
  • 2

1 Answers1

3

I suggest you try something like the following:

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);
}

Update

Added usage of ToTask() to transform the IAwaitable to a Task that can be used with WhenAny.

Hope it helps!

Itay Podhajcer
  • 2,616
  • 2
  • 9
  • 14
  • Thakns man, but I have error in string 'if (Task.WaitAny(result, Task.Delay(1000)) == result)' - Argument 1: Cannot convert from "Microsoft.Bot.Builder.Dialogs.IAwaitable " to "System.Threading.Tasks.Task". I think convert would not be a good idea. – M.Tony Jan 01 '19 at 10:13
  • 1
    See update on how to transform the `IAwaitable` to a `Task` – Itay Podhajcer Jan 01 '19 at 10:29