Microsoft Bot Framework C#异步问题

时间:2017-09-08 18:22:16

标签: c# asynchronous webclient botframework

我遇到一个没有调用函数的问题。我的猜测是它是一个同步问题。

以下是代码:

await context.PostAsync("Foo Bar");

如果我在POST之前或之后将它放到网络服务器上,似乎不会调用下面的函数。

context.Call(new QuestionFourDialog(), this.QuestionFourResumeAfter);

Uri baseUri = new Uri("http://somedomain.com/");
UriBuilder builder = new UriBuilder($"{baseUri}/analytics/message?");

using (WebClient webclient = new WebClient())
{
    webclient.Encoding = System.Text.Encoding.UTF8;
    webclient.Headers.Add("Content-Type", "application/json");

    string postBody = $"{{\"message\": \"{this.answer}\", \"key\": \"7F02D18E-88E7-486D-B51F-550118491CB1\"}}";

    webclient.UploadString(builder.Uri, postBody);
}

有没有办法可以异步调用POST代码或其他方式来解决这个问题?

1 个答案:

答案 0 :(得分:0)

我替换了这一行

webclient.UploadString(builder.Uri, postBody);

webclient.UploadStringAsync(builder.Uri, postBody);

现在它完美无缺。