1
我有以下代码。我试图让按钮主要形式,它可以暂停,继续和停止后台线程下载器上(专用线程线程)暂停后台线程()
Form1.cs的
private AutoResetEvent waitHandle = new AutoResetEvent(true);
private Thread thread;
private void ThreadJob()
{
Downloader download = new Downloader();
download.runDownloader();
}
// THREADS button1 is "Download now"-button
private void button1_Click(object sender, EventArgs e)
{
ThreadStart job = new ThreadStart(ThreadJob);
thread = new Thread(job);
thread.IsBackground = true;
thread.Start();
}
这个代码在Windows上运行跑形成。我对所有这些动作的按钮(暂停,继续,停止)
暂停和继续按钮上的形式
private void btnPause_Click(object sender, EventArgs e)
{
waitHandle.WaitOne(); // Need to pause the background thread
}
private void btnContinue_Click(object sender, EventArgs e)
{
waitHandle.Set(); // Need to continue the background thread
}
问题是按暂停键将冻结的主要形式不是后台线程代码。
,“这是runDownloader()必须能够暂停。”真的帮助:)谢谢。 –