Answer the question
In order to leave comments, you need to log in
Pass multiple variables to Parallel.ForEach?
private void button_Click(object sender, RoutedEventArgs e)
{
z_prox = Convert.ToInt32(textBox.Text);
Task.Factory.StartNew(() => {
testx(accitem, Prox);
});
}
public void testx(string[] accitem, string [] Prox)
{
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = z_prox;
Parallel.ForEach(Prox, options, Prox1 => {indieroyale(Prox1);});
}
Parallel.ForEach(Prox,accitem, options, Prox1 => {indieroyale(Prox1,ck);});
Answer the question
In order to leave comments, you need to log in
/*А нельзя ли просто объединить эти параметры в одну сущность, например так:
class Prox
{
public string[] Prox1 {get;set;}
public int[] Prox2 {get;set;}
}*/
var items = new List<KeyValuePair<string, string>>();
for (int i = 0; i < Prox.Length; i++)
{
items.Add(new KeyValuePair<string, string>(Prox[i], accitem[i]));
}
// с использованием Parallel, если массивы очень огромные
// Parallel.For(0, prox.Length, i => items.Add(new KeyValuePair<string, string>(Prox[i], accitem[i])));
Parallel.ForEach(items, options, p => indieroyale(p.Key, p.Value));
Parallel.For(0, Prox.Length, options, i => indieroyale(Prox[i], accitem[i]));
https://msdn.microsoft.com/en-us/library/system.th... here are the answers!
And what prevents to make of two types 1, in which both will be?
As with events, EventArgs 1 pcs, Sender 1 pcs and that's enough.
Simplified a little
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = Convert.ToInt32(textBox.Text);
Parallel.ForEach(<b>accitem, Prox,</b> options, (Prox1, ck) => {indieroyale(Prox1, ck); });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question