onPaint发射太多次

时间:2012-08-22 12:59:40

标签: winforms wcf winforms-interop

我有一个winforms用户控件,可让用户在面板上编辑工作流程。工作流程由构建块和连线组成,这也是我的用户控件。

当我将应用程序从winforms.exe迁移到另一个WCF应用程序的winform控件时,我注意到CPU使用率攀升至25%(=我的4核心机器的单核心的100%)

CPU在运行时尽快回落到0-1%:

我从任何现有控件清除我的工作流程面板,或

我将屏幕焦点移动到另一个应用程序(并让它在后台运行)或甚至是同一个应用程序中的不同选项卡。

重要的是要说这不会发生在Windows窗体托管应用程序中,只能在WCF中发生。

我看到了一个覆盖基础工作流程块UC的WndProc方法的地方,我也做了,但我仍然不理解WndProc方法的调用次数或者如何使其停止。

我的堆栈看起来像:

  

BaseControls.dll!Ast.Admin.Controls.BaseControl.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})第91行C#       System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)+ 0x1d bytes
      System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)+ 0xaa bytes
      System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd,int msg = 129,System.IntPtr wparam,System.IntPtr lparam)+ 0x6f bytes       System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WindowClass.Callback(System.IntPtr hWnd,int msg,System.IntPtr wparam,System.IntPtr lparam)+ 0x51 bytes
      [原产于管理过渡]
      [管理到原生过渡]
      System.Windows.Forms.dll!System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int dwExStyle,string lpszClassName,string lpszWindowName,int style,int x,int y,int width,int height,System.Runtime.InteropServices.HandleRef hWndParent ,System.Runtime.InteropServices.HandleRef hMenu,System.Runtime.InteropServices.HandleRef hInst,object pvParam)+ 0x3f bytes
      System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams cp)+ 0x22d bytes       System.Windows.Forms.dll!System.Windows.Forms.Control.CreateHandle()+ 0x12c bytes
      System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false)+ 0x89 bytes
      System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl()+ 0x31 bytes
      System.Windows.Forms.dll!System.Windows.Forms.Control.ControlCollection.Add(System.Windows.Forms.Control value = {Ast.Controls.AllianceEnterprise.DataSource})+ 0x1dd bytes
      AdminUC.dll!Ast.Admin.AdminUC.RuleBuilderUC.AddItem(object objData =&#34; C:\ Ast Alliance NextUI \ Bin \ Escalation \ Controls \ Actions \ DataConnector.dll; Ast.Controls.AllianceEnterprise.DataSource&#34; )+ 0x510字节       AdminUC.dll!Ast.Admin.AdminUC.RuleBuilderUC.drawingPanel_DragDrop(object sender = {System.Windows.Forms.Panel},System.Windows.Forms.DragEventArgs e = {System.Windows.Forms.DragEventArgs})+ 0xa0 bytes <登记/>       System.Windows.Forms.dll!System.Windows.Forms.Control.OnDragDrop(System.Windows.Forms.DragEventArgs drgevent)+ 0x73 bytes
      System.Windows.Forms.dll!System.Windows.Forms.Control.System.Windows.Forms.IDropTarget.OnDragDrop(System.Windows.Forms.DragEventArgs drgEvent)+ 0x15 bytes       System.Windows.Forms.dll!System.Windows.Forms.DropTarget.System.Windows.Forms.UnsafeNativeMethods.IOleDropTarget.OleDrop(object pDataObj,int grfKeyState,long pt,ref int pdwEffect = 1)+ 0x5d bytes       [原产于管理过渡]
      [管理到原生过渡]
      System.Windows.Forms.dll!System.Windows.Forms.Control.DoDragDrop(object data,System.Windows.Forms.DragDropEffects allowedEffects)+ 0xed bytes       AdminUC.dll!Ast.Admin.AdminUC.RuleBuilderUC.listView_MouseDown(object sender = {System.Windows.Forms.ListView},System.Windows.Forms.MouseEventArgs e = {X = 16 Y = 6 Button = Left})+ 0x285字节       System.Windows.Forms.dll!System.Windows.Forms.Control.OnMouseDown(System.Windows.Forms.MouseEventArgs e)+ 0x73 bytes
      System.Windows.Forms.dll!System.Windows.Forms.ListView.WmMouseDown(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message},System.Windows.Forms.MouseButtons button,int clicks) + 0x7a字节
      System.Windows.Forms.dll!System.Windows.Forms.ListView.WndProc(ref System.Windows.Forms.Message m)+ 0xf7 bytes       System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)+ 0x1d bytes
      System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)+ 0xaa bytes
      System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd,int msg = 513,System.IntPtr wparam,System.IntPtr lparam)+ 0x6f bytes       [原产于管理过渡]
      [管理到原生过渡]
      WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame})+ 0xb5 bytes       WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)+ 0x3c bytes
      PresentationFramework.dll!System.Windows.Application.RunDispatcher(对象忽略)+ 0x34字节
      PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)+ 0x16f bytes
      PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window窗口)+ 0x33字节       PresentationFramework.dll!System.Windows.Application.Run()+ 0x69字节       Ast Browser.exe!Ast.NextUI.GUI.Shell.App.StartApplication()+ 0x75 bytes
      Ast Browser.exe!Ast.NextUI.GUI.Shell.App.Main(string [] args)+ 0x22b bytes

其中basecontrol是我的工作流程块的基类。

这种情况将永远发生在第二次我将第一块放在面板上,并不像我在屏幕上做任何事情来证明所有这些痛苦。

1 个答案:

答案 0 :(得分:0)

这是做什么的:

[Managed to Native Transition]
 System.Windows.Forms.dll!System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, System.Runtime.InteropServices.HandleRef hWndParent, System.Runtime.InteropServices.HandleRef hMenu, System.Runtime.InteropServices.HandleRef hInst, object pvParam) + 0x3f bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams cp) + 0x22d bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateHandle() + 0x12c bytes

看起来正在调用OnPaint,因为窗口是第一次创建的。

如果这是一个典型的调用堆栈,在拖放应用程序中每秒调用数百次,你真的需要找出原因并停止它......