线程安全的读取拼多多买手订单
This commit is contained in:
1 parent
f00cdee502
commit
ce205c3bf4
2 files changed
+67
-14
No files matched your search
@@ -23,6 +23,40 @@ namespace AllBase.Util
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
_lock = new ReaderWriterLockSlim();
|
||||
}
|
||||
|
||||
public ObservableCollectionThreadSafe(List<T> list) : base((IList<T>)((list != null) ? new List<T>(list.Count) : list))
|
||||
{
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
_lock = new ReaderWriterLockSlim();
|
||||
|
||||
CopyFrom(list);
|
||||
}
|
||||
|
||||
public ObservableCollectionThreadSafe(IEnumerable<T> collection)
|
||||
{
|
||||
if (collection == null)
|
||||
{
|
||||
throw new ArgumentNullException("collection");
|
||||
}
|
||||
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
_lock = new ReaderWriterLockSlim();
|
||||
CopyFrom(collection);
|
||||
}
|
||||
|
||||
private void CopyFrom(IEnumerable<T> collection)
|
||||
{
|
||||
IList<T> items = base.Items;
|
||||
if (collection == null || items == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (T item in collection)
|
||||
{
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user