对我的drawingvisualhost的getvisualchild()的调用次数非常多 [英] Very high number of calls to getvisualchild() of my drawingvisualhost

查看:51
本文介绍了对我的drawingvisualhost的getvisualchild()的调用次数非常多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的DrawingVisualHost存在性能问题。我正在编写一个处理MusicXML文件的应用程序,并在Canvas上绘制乐谱(使用加载的信息)。



简单的画布结构如下:



主画布(通常用于A4纸张大小的页面),

+每行音乐分数的画布(最多6-8),

+自定义面板来安排项目(注释,休息通常是任何音乐项目)

+每个音乐元素项目是Canvas with DrawingVisualHost as children

+ DrawingVisualHost通常包含一两个drawingVisuals



问题是当我在每个光标移动时将鼠标光标移动到Main Canvas区域内时我收到了大量的调用每个DrawingVisualHost GetVisualChild(int index)方法导致大量集合的CPU使用率非常高



这是我的DrawingVisualHost代码:

Hi,
I have performance problem with my DrawingVisualHost. I'm writing an application which processing MusicXML files and draws music score (using loaded information) on Canvas.

Simple Canvas structure below:

Main Canvas (acts like page usually size of A4 paper of sheet),
+ Canvas for each line of music scores (up to 6-8),
+ Custom panel to arrange items(notes,rests generally any music item)
+ Each music element item is Canvas with DrawingVisualHost as children
+ DrawingVisualHost contains usually one-two drawingVisuals

The problem is when I'm moving mouse cursor inside area of Main Canvas on every cursor move I'm getting very large amount of calls to every DrawingVisualHost GetVisualChild(int index) method which cause very high CPU usage with large collections

This is my DrawingVisualHost code:

 public class DrawingVisualHost : FrameworkElement
 {
     private List<Visual> visuals;

     public DrawingVisualHost()
     {
         visuals = new List<Visual>();
         IsHitTestVisible = true;
     }
     protected override Visual GetVisualChild(int index)
     {
         return visuals[index];
     }
     protected override int VisualChildrenCount
     {
         get
         {
             return visuals.Count;
         }
     }
     public void AddVisual(Visual visual)
     {
         visuals.Add(visual);
         AddVisualChild(visual);
     }
}





我尝试了什么:



我花了两天时间试图了解这里发生了什么,代码看起来没问题,没有例外,没有命中测试,没有任何连接到任何画布的MouseEvents ......没有。



当我在这个方法中放置断点并将光标移动到主画布区域时。仅限调用堆栈显示:



What I have tried:

I've spent two days trying to understand what is going on here, code looks ok, no exceptions, no Hit testing, no MouseEvents attached to any Canvas... nothing.

When I placed breakpoint inside this method and I moved cursor on Main Canvas area. Call stack shows only:

MusicXMLScore.exe!MusicXMLScore.Helpers.DrawingVisualHost.GetVisualChild(int index = 1) Line 25

[External code]



关闭外部代码:


with External code filter off:

PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)	
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsOuterSpace(bool renderBounds)
PresentationCore.dll!System.Windows.Media.Visual.CalculateSubgraphBoundsInnerSpace(bool renderBounds = false)
PresentationCore.dll!System.Windows.Media.Visual.VisualDescendantBounds.get()
PresentationCore.dll!System.Windows.Media.Visual.TrySimpleTransformToAncestor(System.Windows.Media.Visual ancestor = {MusicXMLScore.MainWindow}, bool inverse = true, out System.Windows.Media.GeneralTransform generalTransform = null, out System.Windows.Media.Matrix simpleTransform = {System.Windows.Media.Matrix})
PresentationCore.dll!System.Windows.Input.InputElement.TranslatePoint(System.Windows.Point pt, System.Windows.DependencyObject from, System.Windows.DependencyObject to, out bool translated = false)
PresentationCore.dll!System.Windows.Input.InputElement.TranslatePoint(System.Windows.Point pt, System.Windows.DependencyObject from, System.Windows.DependencyObject to)
PresentationCore.dll!System.Windows.Input.MouseDevice.PreNotifyInput(object sender, System.Windows.Input.NotifyInputEventArgs e = {System.Windows.Input.NotifyInputEventArgs})
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = {System.IntPtr}, MS.Internal.Interop.WindowMessage msg = WM_MOUSEFIRST, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr}, ref bool handled = false)
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = {System.IntPtr}, int msg = 512, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr}, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = {System.IntPtr}, int msg = 512, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr}, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler = null)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = {System.IntPtr}, int msg = 512, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr})
[Native to Managed Transition]	
[Managed to Native Transition]	
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame})
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)
PresentationFramework.dll!System.Windows.Application.Run()
MusicXMLScore.exe!MusicXMLScore.App.Main()
[Native to Managed Transition]	
[Managed to Native Transition]	
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args)
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()

推荐答案

好的,经过最后几小时的挖掘,我觉得我找到了原因。我不知道为什么,但当我禁用与物品控制相关的DropShadow效果时,这个效果似乎已经解决了。

Ok, after last hours of digging I think I found cause. I don't know why, but when I disabled DropShadow Effect attached to Items Control which binds to collection of Pages(Main Canvases) the problem seems to be solved.
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    <ItemsControl x:Name="PagesCollection" Margin="0,5,0,5" ItemsSource="{Binding PagesCollection}">
        <!--<ItemsControl.Effect>
            <DropShadowEffect Color="Gray" BlurRadius="5" ShadowDepth="5"/>
        </ItemsControl.Effect>-->
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <helpers:SimpleWrapPanel Margin="10"></helpers:SimpleWrapPanel>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</ScrollViewer>



那么,现在我还有其他问题,在哪里或如何为每个Canvas of PagesCollection添加阴影?


So, now I have other issue, where or how to add shadow to every Canvas of PagesCollection ?


这篇关于对我的drawingvisualhost的getvisualchild()的调用次数非常多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆