代码:
namespace ThreadPause
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ManualResetEvent OnOff = new ManualResetEvent(true);
private void Form1_Load(object sender, EventArgs e)
{
OnOff.Reset();
Task.Run(() =>
{
while (progressBar1.Value < 100)
{
OnOff.WaitOne();
Thread.Sleep(100);
Invoke(new Action(() =>
{
progressBar1.Value++;
}));
}
});
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "暂停")
{
OnOff.Reset();
button1.Text = "开始";
}
else
{
OnOff.Set();
button1.Text = "暂停";
}
}
}
}
标签:Text,Form1,button1,线程,ManualResetEvent,暂停,OnOff
From: https://www.cnblogs.com/zzzyt/p/17360494.html