求问~定时器触发事件影响主窗体问题
代码如下:
public partial class Form1 : Form
{
App timertest;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timertest = new App();
timertest.Boiled += new App.MyEventHandler(changerichtext);
}
public void changerichtext(string sender, EventArgs e)
{
this.richTextBox1.Text = sender;
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = "开始";
timertest.start();
}
}
public class TimerExampleState
{
public int counter = 0;
public System.Threading.Timer tmr;
}
public class App
{
public delegate void MyEventHandler(string sender, EventArgs e);
public event MyEventHandler Boiled; //声明事件
public void start()
{
TimerExampleState s = new TimerExampleState();
//创建代理对象TimerCallback,该代理将被定时调用
TimerCallback timerDelegate = new TimerCallback(CheckStatus);
//创建一个时间间隔为1s的定时器 ,S为输入参数,就是下面CheckStatus调用的参数。
System.Threading.Timer timer = new System.Threading.Timer(timerDelegate, s, 1000, 1000);
s.tmr = timer;
//主线程停下来等待Timer对象的终止
while (s.tmr != null)
Thread.Sleep(0);
&nb