Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Merhabalar,
.Net 3.5 da paralel işlemler ile ilgili kod ararken sizin kodunuz çıktı karşıma. Aşağıdaki gibi bir işlem deniyorum, bazen çalışıyor, bazen unbound array hatası veriyor, bazen result listesine 1000000 değer eklenmesi gerekiyorken 990000~ nesne ekleniyor, ayrıca normal fordan yavaş sürüyor.

int[] range = Enumerable.Range(0, 1000000).ToArray();<br />
           List<double> result = new List<double>();<br />
           Parallel.ForEach(range, i =><br />
                                       {<br />
                                           double d = i + (i - 1000) / 500;<br />
                                           result.Add(d);<br />
                                       });


Hala çalışan düzgün bir parallel döngü kodu bulamadım, yardımcı olursanız çok sevinirim, teşekkürler.
Posted
Updated 2-Mar-10 4:31am
v2

1 solution

I used google translate to understand your question. Parallel will speed up things. What you did is parallel. But i suspect it is not implemented corectly & if you are dealing with large number, i can tell you will have problems in above code. The reason is you have same output (result) but the sequence will be messed up, due to parallel processing. Only way to deal with it is not to use parallel processing here. Technically you can use Array instead of list (as you already know the size of result its 1000000 anyway). And do a result[i] = i + ((double)i-1000)/500;

Read more about threads, you will get better idea how they work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900