0
votes

I am new in Microsoft bot development, so I started to use the examples published on Github by the company. I noticed that some example has disabled a warning in the dialog classes:

#pragma warning disable 1998

if I remove the line, I got the expected message "The async method lacks 'await' operators and will run synchronously..." Thats normal since the examples usually contains method calls such as context.Wait(this.MessageReceivedAsync); where MessageReceivedAsync() is an async method.

I learnt that suppressing warnings is not a good approach and to resolve the cause of the warning would be the preferable. I have the feeling I miss the point here somehow. I would like to understand the concept why did the developer choose to use disable the warning here and not find another way of implementation instead? Should I do the same if I develop similar applications?

Example: https://github.com/Microsoft/BotBuilder-Samples/blob/master/CSharp/capability-SimpleTaskAutomation/Dialogs/RootDialog.cs

1

1 Answers

1
votes

This warning has been put due to the fact that a warning will be thrown by this method in your sample:

public async Task StartAsync(IDialogContext context)
{
    context.Wait(this.MessageReceivedAsync);
}

As you can see this method is async but there is no awaited call inside, hence the warning.

The problem when you try to fix this one is the fact that this StartAsync is the implementation of the IDialog interface of the Bot Framework, which is here:

public interface IDialog<out TResult>
{
    /// <summary>
    /// The start of the code that represents the conversational dialog.
    /// </summary>
    /// <param name="context">The dialog context.</param>
    /// <returns>A task that represents the dialog start.</returns>
    Task StartAsync(IDialogContext context);
}

As you can see the StartAsync method is declared for asynchronous behavior.