0

我需要进入richTextBox1.Lines另一个线程。但我不知道如何安全地穿过线程来获得它。

string[] lines = richTextBox1.Lines;
4

2 回答 2

1

我同意@Hans,您应该从主 UI 线程正确地将其传递到您的线程中。

...但是,因为每个人都喜欢长而难以阅读的单行:

        List<string> lines = new List<string>((string[])richTextBox1.Invoke(new Func<string[]>(delegate { return richTextBox1.Lines; } )) );
        foreach (string line in lines)
        {
            Console.WriteLine(line);
        }
于 2013-05-15T22:24:24.450 回答
0

请查看有关从 Control.BeginInvoke 继承的 RichTextBox.BeginInvoke(Delegate) 的 msdn 帮助。

于 2013-05-15T21:31:18.713 回答