سؤال

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);
    });
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top