线程安全的读取拼多多买手订单

This commit is contained in:
wule_5900x committed 2026-07-30 23:28:08 +08:00
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