是否建议以异步方式引发所有事件,如果 [英] Is it a recommended practice to raise all the events asynchronously if

查看:67
本文介绍了是否建议以异步方式引发所有事件,如果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果类(事件引发对象)对客户端对象(事件的接收者)如何操纵事件的参数不感兴趣,是否建议异步引发所有事件?!

Is it a recommended practice to raise all the events asynchronously if the class (event raising object) does NOT interested on how the parameters of the events are manipulated by the client objects (receivers of the events)?!

请指导我?

推荐答案

不,这不是推荐的做法.

No it's not a recommended practice.

您还必须考虑其他因素,例如:

You have to consider other factors, like:

  • 生成类的线程亲和力要求.
  • 是否涉及UI元素(线程亲和力的一种变化)
  • 响应事件的类是否可以接受多个线程上的并发处理(又名 threadsafe ).
  • 是否涉及线程本地数据(例如Thread.CurrentPrincipal,HttpContext等)
  • 您是否从多线程处理中获得了任何好处.
  • Thread affinity requirements of the generting class.
  • Whether UI elements are involved (a variation on thread affinity)
  • Whether the classes responding to events can accept concurrent processing on multiple threads (aka are they threadsafe).
  • Whether there is thread-local data involved (e.g. Thread.CurrentPrincipal, HttpContext, etc)
  • Whether you are gaining anything from multi-threaded processing.

多线程处理使事情变得复杂.异步事件处理需要多线程处理.仅在购买了东西后才引入复杂性(例如,提高性能,更敏感的用户交互,简化可能会更复杂的其他事情).

Multithreading makes things complicated. Asynchronous event handling requires multithreading. You should only introduce complexity if it buys you something (e.g. improved performance, more responsive user interaction, simplification of something else that would be even more complicated).

在不了解特定情况的详细信息的情况下,不可能建议异步事件是否合适.但是所有事情都是平等的-除非我有充分的理由,否则我会避免异步事件.

Without knowing the details of your specific situation, it's impossible to recommend whether asynchronous eventing is appropriate. But all things being equal - I would avoid asynchronous eventing unless I had a strong reason for it.

这篇关于是否建议以异步方式引发所有事件,如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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