寻找ThreadSafe BindingList [英] Looking For ThreadSafe BindingList

查看:139
本文介绍了寻找ThreadSafe BindingList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不是threadSafe的异步BindingList。我一直在尝试所有wkend使它成为threadSafe但我似乎没有去哪里!有谁知道如何制作BindingList threadSafe或者我可以在哪里找到threadSafe实现?



提前致谢,

-DA

解决方案

使这个线程安全的唯一方法是对add方法应用一个锁:



  void  AddItemToList( object  o)
{
< span class =code-keyword> lock (myBindingList)
{
myBindingList.Add(o);
}
}





如果您正在寻找线程安全集合,请查看系统。 threading.concurrent命名空间。 http://msdn.microsoft.com/en-us/library/dd287108 [ ^ ]这些提供了线程安全的集合。这有帮助吗?


并发容器没有List或BindingList所做的所有方法,因此,使用lock seens是大多数用途的最佳方法。


我知道这个帖子很旧但是也许其他人在看,同步上下文可以帮助。



提供一个线程安全的绑定 - 使用创建列表的synchronizationcontext列表。

https://searchcode.com/codesearch/查看/ 2515598 / [ ^ ]

I have an asynchronous BindingList which isn't threadSafe. I've been trying all wkend to make it threadSafe but I seem to be going no where! Does anyone know how to make BindingList threadSafe or where I can find a threadSafe implementation?

Thanks in advance,
-DA

解决方案

The only way to make this thread safe is to apply a lock on the add method:

void AddItemToList(object o)
{
    lock(myBindingList)
    {
        myBindingList.Add(o);
    }
}



If you are looking for a thread safe collection then take a look at the system.threading.concurrent namespace. http://msdn.microsoft.com/en-us/library/dd287108[^] these provide thread safe collections. does that help?


The concurrent containers don´t have all the methods that a List or a BindingList does, so, using the lock seens to be the best way for most purposes.


I know the post is old but maybe someone else is looking , Synchronization context can help.

Provides a thread-safe binding-list by using the synchronizationcontext where the list was created.
https://searchcode.com/codesearch/view/2515598/[^]


这篇关于寻找ThreadSafe BindingList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆