我正在将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)