开发者

Raising an event in C# from a 2nd thread to the main thread?

开发者 https://www.devze.com 2023-02-05 05:19 出处:网络
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开发者_开发知

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.

0

精彩评论

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