EventHandler类型,没有事件args [英] EventHandler type with no event args

查看:80
本文介绍了EventHandler类型,没有事件args的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们要将数据传递给事件订阅者时,我们使用EventArgs(或CustomEventArgs)。

When we want to pass data to an event subscriber, we use EventArgs (or CustomEventArgs) for this.

.Net提供了一个类型为EventHandler的构建,它使用一个参数,也是构建的EventArgs类的一个实例。

.Net provides a build in type EventHandler that uses as a parameter an instance of EventArgs class that is build in as well.

当我需要通知用户某些操作已经结束的情况下,例如搜索是过度?我不想使用EventArgs,它不会包含任何东西。

What about cases, when I need to notify a subscriber that some action is over, for example search is over? I don't want to even use EventArgs, that won't contain anything.

是否有一个类型用于发信号通知另一个类,而不需要使用空的EventArgs?

Is there a build in type for signaling another class, without the need to use empty EventArgs?

推荐答案

你可以做几件事:


  1. 使用EventHandler和基本的EventArg类 - 确定它是空的,但是这是否受到伤害?

  2. 使用自己的代理,并使用事件MyDelegateWithoutParams MyEvent;

  3. 使用具有IObservable的观察者模式

  4. 让客户端通过一个Action,并调用此操作

  1. youse your normal event with EventHandler and the basic EventArg class - sure it's empty but does this hurt?
  2. make your own delegate and use this with event MyDelegateWithoutParams MyEvent;
  3. use the Observer-Pattern with IObservable instead
  4. let the clients pass a Action do you and call this action

我希望其中一个选择是您的喜好。我使用1和4这种情况(4个主要是只有一个听众。

I hope one of this options is to your liking. I use 1 and 4 for this kind of situation (4 mostly if there will be only one "listener".

PS:我猜2不符合<一个href =http://msdn.microsoft.com/de-de/library/w369ty8x.aspx =noreferrer> .net框架指南,所以也许这不是最好的主意;)

PS: I guess 2 won't conform to the .net framework guidelines so maybe this is not the best idea ;)

这篇关于EventHandler类型,没有事件args的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆