开发者

C#: Calling method in another thread [duplicate]

This question already has answers开发者_如何转开发 here: Closed 11 years ago.

Possible Duplicate:

How to update GUI from another thread in C#?

Following scenario: I have a class with some GUI elements (winforms). This class has a update method which changes things on the controls. I also have a FileSystemWatcher. This object gives me a callback whenever a file changes. In that case I call the update method.

As you might guess this makes the application crash. The reason: the callback from the FileSystemWatcher is in another thread that the one that created the controls. If I then call the update method it can't access the controls.

What is the way to fix this? Thanks!


You should call Control.Invoke or BeginInvoke, see in-depth reference Here


The top voted answer this this Question looks like it might do the trick:

C# Windows Forms Application - Updating GUI from another thread AND class?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜