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.
精彩评论