Home > Net >  C # how to solve the problem of parallel computing thread safe
C # how to solve the problem of parallel computing thread safe

Time:03-19

The code is simple:
The Parallel ForEach (List_R, f=& gt;
{
F.S tr=rc. Get (F.A.T oString (), F.B.T oString ());//rc. The Get () method is a network, return a.T o.T oString () + "-" + a.T o.T oString ();

Jl=JieXi (f.R outeStr);//JieXi is for rc. The Get () returns a string, parse back to a and b

If (f.a!=jl. A | | f.b!=jl. B)
{
//if the resolution is not consistent, return an error

}

});

This code if you use the for order, will not parse the inconsistent problems, but if use parallel computing, can appear return results and input,
What is the good way to avoid this kind of situation?



CodePudding user response:

Try this
 
Foreach (var item in List_R. AsParallel () AsOrdered ())
{

}
  •  Tags:  
  • C#
  • Related