0

I've been looking a lot of sites about "manipulate gui-elements from another thread" and each solution i found was (or looks) completely different than the others... Some solutions were 1-3 lines long and other solutions were 50+ lines long.

Here for example i have 2 different and small working solutions for this. My question is: Which of them is the common solution?

Both of this code-snippets are called from another thread (not the gui-thread).

// Solution 1.)
    frame.rtbChatbox.Invoke(new Action(() => frame.rtbChatbox.AppendText("\n" + line)));

// Solution 2.) 
    frame.rtbChatbox.Invoke((Action)delegate {
       frame.rtbChatbox.AppendText("\n" + line);
    });
user3146246
  • 55
  • 2
  • 8
  • There's a popular anti-pattern to create a background thread which mostly calls back the UI thread on a tight loop, to manipulate the UI elements. Make sure you don't do something like that. – noseratio Feb 17 '14 at 21:45

1 Answers1

0

The two solutions listed are functionally equivalent. They are two different syntaxes which are each used to create an anonymous method.

Use whichever one you want.

Servy
  • 202,030
  • 26
  • 332
  • 449