子線程裡有循環,如何立即終止線程
private void button1_Click(object sender, EventArgs e)
{
label10.Text = "正在打開目標地址,請稍後..";
label10.Refresh();
button1.Enabled = false;
isAbort = false;
thread2 = new Thread(post);
thread2.Start();
}
<span id="more-682"></span>
/// <summary>
/// 回帖操作
/// </summary>
private void post()
{
....
//這裡是循環回帖
for(...)
{
if (isAbort)
return;
...
}
}
//終止線程
private void button2_Click(object sender, EventArgs e)
{
//停止工作
try
{
isAbort = true;
button1.Enabled = true;
webBrowser.Visible = false;
label10.Text = "停止運行";
label10.Refresh();
}
catch
{
MessageBox.Show("已經是停止狀態");
}
}
摘自 http://www.xssxss.com/fuck/682.xss