Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# N服务总线处理程序触发问题_C#_Asp.net_.net_Nservicebus - Fatal编程技术网

C# N服务总线处理程序触发问题

C# N服务总线处理程序触发问题,c#,asp.net,.net,nservicebus,C#,Asp.net,.net,Nservicebus,我的项目正在升级到使用nservice总线版本7。其中一个处理程序正在并发执行。经过分析发现,有一个行为代码被编写并在处理程序选择后得到执行。然后下一个处理程序将被执行。这将在循环中执行,并且不会结束 public class GatewayPublishBehavior : Behavior<IIncomingLogicalMessageContext> { public override async Task Invoke(IIncomingLogicalMessageCo

我的项目正在升级到使用nservice总线版本7。其中一个处理程序正在并发执行。经过分析发现,有一个行为代码被编写并在处理程序选择后得到执行。然后下一个处理程序将被执行。这将在循环中执行,并且不会结束

public class GatewayPublishBehavior : Behavior<IIncomingLogicalMessageContext>
{

  public override async Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next)
  {
    //// custom logic before calling the next step in the pipeline.
    await next().ConfigureAwait(false); 
    // custom logic after all inner steps in the pipeline completed.
    await context.Publish(context.Message.Instance, 
  this.RetrieveAndGetSendOptions(context));
  }
}
公共类网关PublishBehavior:行为
{
公共重写异步任务调用(IIncomingLogicalMessageContext上下文,Func next)
{
////在调用管道中的下一步之前,自定义逻辑。
wait next().configurewait(false);
//管道中所有内部步骤完成后的自定义逻辑。
等待context.Publish(context.Message.Instance,
this.RetrieveAndGetSendOptions(上下文));
}
}

上面是行为代码。不确定为什么处理程序会被多次执行。

与此代码完全相同

public void Whatever()
{
  Whatever();
}

无止境的循环。只需删除发布。你为什么加上那一行?你喜欢复制品吗?因为你两次发布了完全相同的问题。试图在StackOverflow内部创建递归循环

看起来你并没有发布完整的行为守则。行为的文档可以在这里找到:如果您正确且只执行了一次
wait next()
,并且没有其他奇怪的行为,那么它不应该只对同一消息实例执行任何处理程序两次。@gnud完整的代码如下所示。public override async Task Invoke(IIncomingLogicalMessageContext,Func next){///在调用管道中的下一步之前的自定义逻辑。wait next().configurewait(false);//在管道中的所有内部步骤完成之后的自定义逻辑。wait context.Publish(context.Message.Instance,this.RetrieveAndGetSendOptions(context));}@DennisvanderStelt完整代码如下。公共重写异步任务调用(IIncomingLogicalMessageContext,Func next){///在调用管道中的下一步之前自定义逻辑。wait next().ConfigureWait(false);//管道中所有内部步骤完成后的自定义逻辑。等待上下文。发布(context.Message.Instance,this.RetrieveAndGetSendOptions(context));}我在另一篇文章中做了。谢谢。我也注意到了同样的情况。谢谢你的回答。行为中的上下文标题正在修改。