定义了一个全局集合
private List<Thread> _testThreads = new List<Thread>();
时钟中有如下一段代码
private void tmrTest_Tick(object sender, EventArgs e)
{ for (int i = 0; i < _testThreads.Count; i++)//如果定时器到时,但做通讯测试的线程还没有结束
{
if (_testThreads[i].IsAlive)
{
_testThreads[i].Join();
}
} Thread.Sleep(350); //用多线程进行通讯测试
for (int index = 0; index < _seiPcbas.Count; index++)
{
_seiPcbas[index].SetTestCondition(cmbCommand.Text, _repeatTimes, _repeatInterval,
new CallBackDelegate(CallBackRecord));
Thread threadTest = new Thread(new ThreadStart(_seiPcbas[index].TestReadCommand));
_testThreads.Add(threadTest);
threadTest.Start();
}
}想在点击"停止"按钮时,首先停止时钟,然后终止线程或等待线程结束,但用Join不动了,用Abort又除出现
如下错误:
未处理 System.ObjectDisposedException
Message="已关闭 Safe handle"
Source="mscorlib"
ObjectName=""
StackTrace:
在 Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
在 System.Threading.EventWaitHandle.Set()
在 System.IO.Ports.SerialStream.AsyncFSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped)
在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)请高手指教
private List<Thread> _testThreads = new List<Thread>();
时钟中有如下一段代码
private void tmrTest_Tick(object sender, EventArgs e)
{ for (int i = 0; i < _testThreads.Count; i++)//如果定时器到时,但做通讯测试的线程还没有结束
{
if (_testThreads[i].IsAlive)
{
_testThreads[i].Join();
}
} Thread.Sleep(350); //用多线程进行通讯测试
for (int index = 0; index < _seiPcbas.Count; index++)
{
_seiPcbas[index].SetTestCondition(cmbCommand.Text, _repeatTimes, _repeatInterval,
new CallBackDelegate(CallBackRecord));
Thread threadTest = new Thread(new ThreadStart(_seiPcbas[index].TestReadCommand));
_testThreads.Add(threadTest);
threadTest.Start();
}
}想在点击"停止"按钮时,首先停止时钟,然后终止线程或等待线程结束,但用Join不动了,用Abort又除出现
如下错误:
未处理 System.ObjectDisposedException
Message="已关闭 Safe handle"
Source="mscorlib"
ObjectName=""
StackTrace:
在 Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
在 System.Threading.EventWaitHandle.Set()
在 System.IO.Ports.SerialStream.AsyncFSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped)
在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)请高手指教
解决方案 »
- datagridview添加了自定义控件后,拖动滚动条时控件如何实时的改变当前位置
- 怎么把有子父级关系的表查询一张表
- 急救:XML 文档(2, 2)中有错误。
- 这条语句哪里有问题,查了半天没找见,请大师帮助。
- WebRequest对象的GetResponse方法一直丢出远程服务器返回错误: (401) 未经授权的异常
- 如何用C#编写这些代码?
- 自定义属性Collection的设计时支持???
- C#如何获取多个物理驱动器的型号和编号???
- 通过c#操作“网上邻居”?
- 救救我!安裝FrontPage 2000 Server Extensions QFE?
- 高手进来看
- 我在做WEBSERVICE出现一点小问题,关于压缩的
你在Timer中起线程,而且起了多个线程,不明白你要干啥???这样的写法挺奇怪的,希望能说明你要干什么