.NET 4.x Недопустимая операция в нескольких потоках - C#
Формулировка задачи:
Dictionary<string, string> accounts = new Dictionary<string, string>();
Application.DoEvents();
foreach (string combo in File.ReadAllLines("proxy.txt"))
{
string[] values = combo.Split(':');
if (values.Length >= 2 && !accounts.ContainsKey(values[0]))
accounts.Add(values[0], values[1]);
Application.DoEvents();
var sync = SynchronizationContext.Current;
new Thread(_ => {sync.Post(__ => richTextBox1.Text = values[0] + ":" + values[1], null);}).Start(); private void button1_Click(object sender, EventArgs e)
{
Thread th_1 = new Thread(sendspace);
Thread th_2 = new Thread(sendspace);
Thread th_3 = new Thread(sendspace);
Thread th_4 = new Thread(sendspace);
th_1.Start();
th_2.Start();
th_3.Start();
th_4.Start();
th_1.Join();
th_2.Join();
th_3.Join();
th_4.Join();
}Решение задачи: «.NET 4.x Недопустимая операция в нескольких потоках»
textual
Листинг программы
Char[] pwdChars = new Char[36] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
textBox2.Text = String.Empty;
for (int i = 0; i < 6; i++)
new Thread(_ => { sync.Post(__ => textBox2.Text += pwdChars[rnd.Next(0, 35)], null); }).Start();