Raising an event in C# from a 2nd thread to the main thread?
Let's say we have the main class and another class with some custom events called OnFoo
.
Now, the second class has a seperate thread that should call these events, which the main thread开发者_开发知识库 should be able to hook into. But as soon as those events are raised, the main class tries to do something on itself that isn't possible, since the event raised function is actually still in that second thread.
How do I raise OnFoo
so the main class can change properties of itself when the event is raised?
PS: I have read about Invoke and BeginInvoke, but haven't had any success with them.
精彩评论