- 959 名前:デフォルトの名無しさん (ワッチョイ 7f94-4hBO) mailto:sage [2016/12/24(土) 19:04:14.66 ID:iV5eYun00.net]
- while(true)で無限にTaskを作るとOutOfMemoryExceptionになるから
Parallel使って10個ずつくらいに制限して、 TextBoxへの書き込みにはProgressを使うとこんな感じ private void button1_Click_1(object sender, EventArgs e) { IProgress<string> progress = new Progress<string>(text => { TextBox1.Text += text; }); Task.Run(() => { while (true) { Parallel.For(0, 10, i => { System.Threading.Thread.Sleep(3000); progress.Report("a"); }); } }); }
|

|