本文介绍了多线程订阅同一事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么时候会发生10个线程将订阅同一事件和事件触发? 哪个线程将它捡起来?
What will happen when 10 threads will subscribe to the same event and the event fires? Which thread will pick it up?
推荐答案线程的不订阅事件,物体做。当事件触发,所有的已注册的处理程序在同一个线程上执行(即引发事件的一种)。有没有内置工具对事件进行触发多个线程。
Thread's don't subscribe to events, objects do. When an event fires, all of the registered handlers execute on the same thread (the one that raised the event). There's no built-in facility for events to fire on multiple threads.
一个处理器可以选择将事件信息转发到一个单独的线程,如果需要的话,但是这不是一部分事件调度的内置机制。
A handler can choose to forward the event information to a separate thread, if desired, but that's not part of the built-in mechanism of event dispatch.
更多推荐
多线程订阅同一事件
发布评论