public partial class Form1 : Form
{
static public bool flag;
public Form1()
{
InitializeComponent();
}
static public void Monitor()
{
string mystring = "hello!";
for (int i = 0; i < mystring.Length; i++)
{
if (flag == false) //马上结束
break;
else
MessageBox.Show(mystring[i].ToString());
}
}
private void 开始_Click(object sender, EventArgs e)
{
timer1_Tick(null,null); //立即开始
timer1.Enabled = true;
flag = true;
}
private void 结束_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
flag = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
Thread threadMonitor = (new Thread(new ThreadStart(Monitor)));
threadMonitor.Start();
}
}