主窗口开始运行后启动一个线程,定时刷新窗口需要的数据,在主窗口的Dispose中终止,但是窗口关闭时会弹出个错误:正在终止线程,是不是这种终止方式不对啊?
protected override void Dispose(bool disposing)
{
if (RefreshThread != null)
{
bRefreshThreadRuning = false;
RefreshThread.Abort();
}
}
public void RefreshThreadFunc()
{
while (true)
{
if (!bRefreshThreadRuning)
continue;
//时间间隔控制
//....
try
{
"需要的操作"
DisplayInfoRefresh();
//
}
catch (Exception e)
{
MessageBox.Show(e.Message, "bRefreshThread ERROR");//窗口关闭时此处检测到错误
}
}
}