- C#, C♯, C#相談室 Part90 [無断転載禁止]©2ch.net
396 :デフォルトの名無しさん[sage]:2016/04/04(月) 16:16:53.43 ID:43ub7UWC - using System;
using System.Threading; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { private Thread thread = null; private bool enabled = false; private int count = 0;
| - C#, C♯, C#相談室 Part90 [無断転載禁止]©2ch.net
397 :デフォルトの名無しさん[sage]:2016/04/04(月) 16:17:07.66 ID:43ub7UWC - public Form1()
{ InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { enabled = true; thread = new Thread(new ThreadStart(() => { while (enabled) { count++; this.Invoke(new Action(() => { this.label1.Text = count.ToString(); })); Thread.Sleep(100); } })); thread.Start(); }
| - C#, C♯, C#相談室 Part90 [無断転載禁止]©2ch.net
398 :デフォルトの名無しさん[sage]:2016/04/04(月) 16:17:14.76 ID:43ub7UWC - private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{ if (thread != null) { enabled = false; thread.Join(); thread = null; } } } }
| - C#, C♯, C#相談室 Part90 [無断転載禁止]©2ch.net
399 :デフォルトの名無しさん[sage]:2016/04/04(月) 16:17:33.12 ID:43ub7UWC - このコードでフォーム閉じるときに高確率でフリーズするんだが原因は?
一時停止するとthread.Join()のところで止まってる。
|
|