Je me demande s'il existe un moyen de convertir ceci afin qu'il soit plus performant en utilisant un Parallel.For par exemple.Ce code WPF pourrait-il bénéficier de Parallel.For et comment?
public FrameworkElement FindIntersectingElement(Rect rectangle, UIElement activeElement)
{
foreach (var child in this.Children)
{
if (child != activeElement)
{
if (GetBounds(child as FrameworkElement, this).IntersectsWith(rectangle))
{
return child as FrameworkElement;
}
}
}
return null;
}
public Rect GetBounds(FrameworkElement of, FrameworkElement from)
{
GeneralTransform transform = null;
transform = of.TransformToVisual(from);
return transform.TransformBounds(new Rect(0, 0, of.ActualWidth, of.ActualHeight));
}
Des suggestions?
Merci, ça fonctionne très Et avec un grand nombre d'éléments, je vois en effet une accélération (test sur une machine à 8 coeurs) .La restriction de l'affinité à un seul noyau montre la différence e aussi bien – TimothyP
Je ne pense pas que la distribution (IEnumerable) fonctionnera, puisque UIElementCollection n'est pas un type générique? –
@Chris, Timothy a déjà signalé que cela fonctionne. –