您的位置:首页 > 其它

线程间操作无效 从不是创建控件 的线程访问它。——解决方法

2010-09-29 12:58 330 查看
从VS2005开始就不允许非创建此控件的线程来调用它,那么解决方法是在该控件所在窗体里加上一句话:
CheckForIllegalCrossThreadCalls = false;

private void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
//信号量
signel sgl = new signel(10);

//新建一个队列缓冲区
Queue<int> que = new Queue<int>(10);
Reader readerThread = new Reader(sgl,que,this);
Writer writerThread = new Writer(sgl,que,this);
//开启两个线程
Thread tRead = new Thread(readerThread.Process);
Thread tWrite= new Thread(writerThread.Process);
tRead.Start();
tWrite.Start();
}

www.cnhgds.com www.wanyouc.com www.yunweis.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐