Bick
Bick

Reputation: 18511

Winforms - Invoking a method in another thread

What is the best practice to invoke a method in a different thread from a winform button so the ui doesn't freeze or creates a delay?

Upvotes: 2

Views: 7278

Answers (4)

Oliver
Oliver

Reputation: 45071

In a first step start with

If this doesn't meet your requirements or you need more advanced stuff you should take a look into one of these:

Upvotes: 6

Alex
Alex

Reputation: 8937

You can do like this

 Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
 {         
      //DO SOMETHING         
 }

Upvotes: -1

Tommaso Belluzzo
Tommaso Belluzzo

Reputation: 23675

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

Upvotes: 0

Otiel
Otiel

Reputation: 18743

Invoke((MethodInvoker) delegate {
    DoSomething();
});

Upvotes: 3

Related Questions