-1

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!

Community
  • 1
  • 1
Mistefix
  • 113
  • 2
  • 4
  • 6

2 Answers2

1

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

Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
0

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?

Community
  • 1
  • 1
Russ Clarke
  • 17,511
  • 4
  • 41
  • 45