Hello,
i'm trying to loop through all my controls using Parallel.Foreach but i'm having some problems... I thought I was going to have no problems cause the ControlCollection class implements IEnumerable...
This is what I do without Parallel:
foreach (Control c in ascx.Controls)
{
if (c is Dynamic.Controls.UnoN && UnaNaAcumulados.IndexOf(c.ID+",")==-1)
{
UnaNaAcumulados += c.ID + ",";
Control caux = (Control)this.LoadControl("~/Datos/UaN_" + c.ID + ".ascx");
UaNNames(caux);
}
}
And I'm trying to do the same with parallel, something like this:
Parallel.ForEach<Control>(ascx.Controls, c => {
if (c is Dynamic.Controls.UnoN) {
UnaNaAcumulados += c.ID + ",";
Control caux = (Control)this.LoadControl("~/Datos/UaN_" + c.ID + ".ascx");
UaNNames(caux);
}
});
But it says that ControlCollection cannot be converted to OrderablePartitioner.
Any ideas?? I've been looking for some help but i'm stuck.
Thanks a lot in advance.
Problem Looping controls using Parallel.foreach
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Ruben Vera2 pointsPosted Jun 10, 2010, 3:38 AM EDT
using System.Linq;
Parallel.ForEach<Control>(ascx.Controls.Cast<Control>(), ...);
So now it's working perfectly :)