简体   繁体   中英

How to determine an EventHandler's thread?

I have an event, which is normally raised asynchronously, like this:

foreach (EventHandler eventHandler in Event.GetInvocationList())
{
   eventHandler.BeginInvoke(sender, e, EndRaiseEvent, eventHandler);
}

Now there might also be listeners who are on the same thread as the one which is raising the event, and in that case I want the event to be raised synchronous (without BeginInvoke), but how do I differentiate those in the InvocationList?

You dont need to. There is not meaning of other listeners running on "a different thread". When an event is raised, if you are registered to it then it dosen't matter on what thread it was raised on, you will be called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM