How can to set the wait time await result [duplicate]












0
















This question already has an answer here:




  • Asynchronously wait for Task<T> to complete with timeout

    12 answers




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?










share|improve this question















marked as duplicate by Alexei Levenkov c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 11:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • Asynchronously wait for Task<T> to complete with timeout

      12 answers




    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?










    share|improve this question















    marked as duplicate by Alexei Levenkov c#
    Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Jan 1 at 11:26


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0


      0







      This question already has an answer here:




      • Asynchronously wait for Task<T> to complete with timeout

        12 answers




      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?










      share|improve this question

















      This question already has an answer here:




      • Asynchronously wait for Task<T> to complete with timeout

        12 answers




      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?





      This question already has an answer here:




      • Asynchronously wait for Task<T> to complete with timeout

        12 answers








      c# async-await botframework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 10:02









      Nkosi

      117k17134200




      117k17134200










      asked Jan 1 at 9:50









      M.TonyM.Tony

      62




      62




      marked as duplicate by Alexei Levenkov c#
      Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Jan 1 at 11:26


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Alexei Levenkov c#
      Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Jan 1 at 11:26


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          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!






          share|improve this answer


























          • 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 <object>" to "System.Threading.Tasks.Task". I think convert would not be a good idea.

            – M.Tony
            Jan 1 at 10:13






          • 1





            See update on how to transform the IAwaitable to a Task

            – Itay Podhajcer
            Jan 1 at 10:29


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          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!






          share|improve this answer


























          • 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 <object>" to "System.Threading.Tasks.Task". I think convert would not be a good idea.

            – M.Tony
            Jan 1 at 10:13






          • 1





            See update on how to transform the IAwaitable to a Task

            – Itay Podhajcer
            Jan 1 at 10:29
















          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!






          share|improve this answer


























          • 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 <object>" to "System.Threading.Tasks.Task". I think convert would not be a good idea.

            – M.Tony
            Jan 1 at 10:13






          • 1





            See update on how to transform the IAwaitable to a Task

            – Itay Podhajcer
            Jan 1 at 10:29














          3












          3








          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!






          share|improve this answer















          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!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 1 at 10:28

























          answered Jan 1 at 10:01









          Itay PodhajcerItay Podhajcer

          2,0091413




          2,0091413













          • 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 <object>" to "System.Threading.Tasks.Task". I think convert would not be a good idea.

            – M.Tony
            Jan 1 at 10:13






          • 1





            See update on how to transform the IAwaitable to a Task

            – Itay Podhajcer
            Jan 1 at 10:29



















          • 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 <object>" to "System.Threading.Tasks.Task". I think convert would not be a good idea.

            – M.Tony
            Jan 1 at 10:13






          • 1





            See update on how to transform the IAwaitable to a Task

            – Itay Podhajcer
            Jan 1 at 10:29

















          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 <object>" to "System.Threading.Tasks.Task". I think convert would not be a good idea.

          – M.Tony
          Jan 1 at 10:13





          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 <object>" to "System.Threading.Tasks.Task". I think convert would not be a good idea.

          – M.Tony
          Jan 1 at 10:13




          1




          1





          See update on how to transform the IAwaitable to a Task

          – Itay Podhajcer
          Jan 1 at 10:29





          See update on how to transform the IAwaitable to a Task

          – Itay Podhajcer
          Jan 1 at 10:29





          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules