请问一个关于多线程的问题
我自定义了一个类A
public class A
{
public string pp = "sfaf ";
Thread _thread;
public event EventHandler OnChanged = null;
private void Do()
{
while (true)
{
StateChanged();
Thread.Sleep(1000);
}
}
public void Start()
{
StateChanged();
_thread = new Thread(new System.Threading.ThreadStart(Do));
_thread.Start();
}
public void Stop()
{
StateChanged();
if (_thread != null)
_thread.Abort();
}
}
其中使用了事件委托,我在窗体Form里面 这样操作:
private void button2_Click(object sender, EventArgs e)
{
k = new A();
k.OnChanged += new EventHandler(tt);
k.Start();
}
void tt(object obj, EventArgs ea)
{