이것은 현재 창을 고정시키는 코드입니다. 이 양식을 동결하지 않는 방법.C# 스레드가 고정 창을 호출합니다.
public partial class Form1 : Form
{
Thread t;
int s = 0;
public Form1()
{
InitializeComponent();
label2.Text = "Push the Button";
button1.Text = "Push me!";
button1.Click += new EventHandler(button1_Click);
this.Controls.Add(label2);
this.Controls.Add(button1);
}
void button1_Click(object sender, EventArgs e)
{
t = new Thread(new ThreadStart(RunMe));
t.Start();
}
private void RunMe()
{
if (!InvokeRequired)
{
while(true)
{
label2.Text = s.ToString();
s++;
Task.Delay(10000).Wait(10000);
}
}
else
{
Invoke(new ThreadStart(RunMe));
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
'Invoke'는 UI 스레드에서 일부 코드를 실행하므로 UI 스레드에서 * 전체 무한 루프 *를 실제로 실행하므로 영구적으로 차단됩니다. – Chris