Question

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);
    });
Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top