有没有人写了一个线程安全的BindingList&LT; T&GT;? [英] Has anyone written a thread-safe BindingList<T>?
本文介绍了有没有人写了一个线程安全的BindingList&LT; T&GT;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前得到的异常在多个线程修改一个IBindingList的时候。有没有人有一个线程安全的版本之前,我写我自己?
I am currently getting exceptions when modifying an IBindingList on multiple threads. Does anyone have a threadsafe version before I write my own?
推荐答案
我想你会发现这是一个非常艰难的任务。较容易的路径将是一个锁定
prevent多线程访问:
I think you'll find this an incredibly difficult task. The easier path would be to prevent multiple-thread access with a lock
:
void AddItemToList(object o)
{
lock(myBindingList)
{
myBindingList.Add(o);
}
}
看那锁定声明文档获取更多信息。
这篇关于有没有人写了一个线程安全的BindingList&LT; T&GT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文