Parallel.Foreach不会处理所有记录,而是每次都会处理随机数
lock
我已经尝试过,但是会降低性能。它是线程安全的吗?
public void PushUKRecordToCB(List<UkDbModel> UKRecordDetailsObj)
{
var bucket = UKProcessor.ConnectToCB();
Console.WriteLine("Connection established with CB " + DateTime.Now);
Parallel.ForEach(UKRecordDetailsObj, item =>
{
Guid flag = Guid.NewGuid();
var document = new Document<dynamic>
{
Id = "UK: " + item.DelPntNr + flag,
Content = item
};
var upsert = bucket.Insert(document);
});
}