Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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# 带有多线程的EventAggregator_C#_.net_Windows_Winforms_Events - Fatal编程技术网

C# 带有多线程的EventAggregator

C# 带有多线程的EventAggregator,c#,.net,windows,winforms,events,C#,.net,Windows,Winforms,Events,我对鳄鱼有点小问题,让我解释一下 public class doSomething { public doSomething() { Action<AddEvent> GetAddSolution = s => this.Add(s.a, s.b); IEventAggregator.GetEvent<AddEvent>().Subscribe(GetAddSolution); } public vo

我对鳄鱼有点小问题,让我解释一下

public class doSomething
{
    public doSomething()
    {
        Action<AddEvent> GetAddSolution = s => this.Add(s.a, s.b);
        IEventAggregator.GetEvent<AddEvent>().Subscribe(GetAddSolution);
    }

    public void Add(int a, int b)
    {
        IEventAggregator.GetEvent<AddSolutionEvent>().Publish(new AddSolutionEventArgs(a + b));
    }
}
公共类doSomething
{
公共剂量测定法()
{
Action GetAddSolution=s=>this.Add(s.a,s.b);
IEventAggregator.GetEvent().Subscribe(GetAddSolution);
}
公共无效添加(内部a、内部b)
{
IEventAggregator.GetEvent().Publish(新的AddSolutionEventArgs(a+b));
}
}
让上面是一个演示服务,在我的例子中,它是一个长时间运行的服务,现在如果我有多个线程使用EventAggrigator调用Add(a,b),那么发布请求的最后一个线程将获得所有响应

如何将响应返回到发布请求事件的线程

请提供指导


提前谢谢。

我自己得到了答案,很简单,在中使用事件过滤器。筛选器委托筛选事件