我正在使用bot框架c#。 RootDialoge的start async方法正在将调用转发到新类,稍后我想基于JSON文件重复调用该类。该类不会在context.Wait()处等待第一次迭代,但可以在下一次迭代中正常工作。
能否请您告诉我这些线程在内部如何工作以及为什么它不能在第一次执行时就等待输入。
RootDialog
public async Task StartAsync(IDialogContext context)
{
callJSON(context);
return;
}
private async Task callJSON(IDialogContext context)
{
//It will call LUIS API & get topScoringIntent
context.Call(new InstallSoftwareDyanamicFlow(topScoringIntent), this.ResumeAfterInstallSoftware);
}
InstallSoftwareDyanamicFlowDialog:
public async Task StartAsync(IDialogContext context)
{
await callDynamicFlow(context);
return;
}
public async Task callDynamicFlow(IDialogContext context)
{
// It will get details from configuration file and pass-on one by one value using counter
context.Call(new CommonDialog(inputToIterate[counter].userInput, inputToIterate[counter].objectTypeRef, inputToIterate[counter].valuesToList, inputToIterate[counter].customMessage), this.ResumeAfterInstallSoftware1);
}
CommonDialog Class:
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync(customMessage);
**context.Wait(ResumeAfterStartAsync);**
}
public virtual async Task<IDialogContext> ResumeAfterStartAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var receivedResult = await result;
var output = (JObject.Parse(((JValue)((JToken)JsonConvert.SerializeObject((await result)))).ToString()))["value"][userInput1];
var value = await result;
await context.PostAsync(value.ToString());
return context;
}
在此ResumeAfterStartAsync上,它直接出现而无需等待用户仅在第一次迭代时输入值,即对于counter = 1,但对于counter = 2可以正常工作,依此类推。