locked
Call Async Task method from Timer Control RRS feed

  • Question

  • User-725520357 posted

    <audio class="audio-for-speech"></audio>

    Hi Gurus,

      I have a Async Task method - IntroStepAsync , which i need to call this from c# timercontrol every 5 seconds. Please help me how to call the task method from timer control with parameters.

    Below is the c# code which needs to be called from timer control.

    private async Task<DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
     {

                if (!_luisRecognizer.IsConfigured)
                {
                    return await stepContext.NextAsync(null, cancellationToken);
                }

                var messageText = "Welcome";
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
      }

    Thanks

    Thursday, May 20, 2021 4:51 PM

All replies

  • User-939850651 posted

    Hi prasanth100,

    I'm not sure if you are looking for something like this:

    protected void Timer1_Tick(object sender, EventArgs e)
            {
                res.Text += DateTime.UtcNow;
                Task.Run(async () =>
                {
                    DialogTurnResult result = await IntroStepAsync(stepContext, cancellationToken);
                });
            }
    
            private async Task<DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
            {
    
                if (!_luisrecognizer.isconfigured)
                {
                    return await stepContext.NextAsync(null, cancellationToken);
                }
    
                var messageText = "Welcome";
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
            }

    If I misunderstood anything, could you provide more details?

    Best regards,

    Xudong Peng

    Friday, May 21, 2021 6:15 AM