Parallel.Foreach保存随机记录数而不是实际数

时间:2019-05-14 15:13:15

标签: c# .net

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);            
    });
}

0 个答案:

没有答案