小编laz*_*per的帖子

Parallel.ForEach没有按预期工作C#

我正在将ForEach替换为Parallel.ForEach.ForEach工作正常并按预期给出结果,其中Parallel.ForEach给出了意想不到的结果.

            string[] ids= { };
            string input="AA;AA;111;T#BB;BB;222;T#CC;CC;333;F";
            string typeId, type, value;
            typeId= type=value=string.Empty;
            bool isValid = false;
            if (input.Contains("#"))
            { ids = input.Split('#'); }
            else
            { ids = new string[] { input };}

//using ForEach ,it's working fine,datas are inserted in DB table properly.
            foreach (var id in ids)
            {
                if (id.Contains(";"))
                {
                    var IdInfo = id.Split(';');
                    if (IdInfo[0] != null)
                    {
                        typeId = Info[0];
                    }

                    if (IdInfo.Length >= 2)
                    { type = IdInfo[1]; }

                    if (IdInfo.Length >= 3)
                    { …
Run Code Online (Sandbox Code Playgroud)

c# task-parallel-library

1
推荐指数
1
解决办法
386
查看次数

标签 统计

c# ×1

task-parallel-library ×1