开发者

Registering an event from different thread

开发者 https://www.devze.com 2022-12-25 04:16 出处:网络
I have a questi开发者_如何学运维on regarding events in c#. Lets say I have an object obj1 of a class that exposes an event, and this object is running on thread t1. Now on different thread t2, there i

I have a questi开发者_如何学运维on regarding events in c#. Lets say I have an object obj1 of a class that exposes an event, and this object is running on thread t1. Now on different thread t2, there is another object called obj2 that is registered for the event of obj1.

Is it promised that obj2 will get the event when it will be raised? thanks.


Yes. However, the event will be raised (which means the event handler will run) on the thread of the method that raises it. In your case, this will be raised on t1.

If the "obj2" object requires that it's code work on t2, you'll have to handle that via marshaling. This is important if "obj2" is a UI element, for example.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号