There is an application with a very large visual tree. For some tasks, I implemented a mechanism that allows you to memorize the entire visual tree into a set of xml files.
I would like to speed up this mechanism. Now it works for independent parts of the interface, so I decided to put the recording of each interface part in the xml file into a separate stream.
The problem is to traverse the visual tree from a non-UI thread. WPF does not allow a third-party thread to access an item that it does not own ( InvalidOperationException ).
In such situations, I usually use Dispatcher.Invoke or Dispatcher.BeginInvoke . In the case of this task, this does not make sense, because by delegating execution through these methods everything will still be executed in the same (interest) stream, and I will not get any performance gain.
Question
Is it possible in some way to bypass the visual tree from several threads at once? Perhaps someone faced with such a task? I would be grateful for any suggestions and help.
UPD:
Most of the time it takes to get the list of properties from DependencyObject, the code to get the list of properties:
private static List GetDependencyProperties (DependencyObject obj)
{ List<DependencyProperty> result = new List<DependencyProperty>(); PropertyDescriptorCollection attCollect = TypeDescriptor.GetProperties(obj, new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) }); foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(obj, new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) })) { DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(pd); if (dpd != null && _filter.IsValidProperty(dpd.DependencyProperty.Name, obj.GetType().Name, dpd.DependencyProperty.OwnerType.Name)) { result.Add(dpd.DependencyProperty); } } return result; } _filter is a wrapper over a Dictionary that stores a list of excluded properties.