是C#事件同步吗? [英] are C# events synchronous?

查看:440
本文介绍了是C#事件同步吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题有两个部分:


  1. 提高事件阻止线程,或者是否异步开始执行EventHandler,并且线程在同一时间继续进行?

  1. Does raising an event block the thread, or does it start execution of EventHandlers asynchronously and the thread goes continues on at the same time?

是否单独的EventHandlers 订阅事件)一个接一个地同步运行,或者它们是否异步运行,而不保证其他人不同时运行?

Are the individual EventHandlers (subscribed to the event) run synchronously one after another, or are they run asynchronously with no guarantee that others aren't running at the same time?


推荐答案

这是一般的答案,反映了默认行为:

This is a general answer and reflects the default behavior:


  1. 是的,它阻止线程,如果订阅事件的方法不是异步的。

  2. 它们一个接一个执行。这有另一个转折:如果一个事件处理程序引发异常,那么尚未执行的事件处理程序将不会执行。

说完每个提供事件的类都可以选择异步地实现它的事件。 IDesign 提供了一个名为 EventsHelper ,这简化了这一点。

Having said that, every class that provides events can choose to implement its event asynchronously. IDesign provides a class called EventsHelper that simplifies this.

[注意] / strong>此链接需要您提供一个电子邮件地址来下载EventsHelper类。

这篇关于是C#事件同步吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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