WPF .NET3.5 C# 处理对象问题

blu*_*lub 1 .net c# wpf memory-leaks wpf-controls

我的应用程序 WPF C#.NET 3.5 VS2008 在一台客户计算机上遇到了一些问题。\n我的应用程序在不同的 Windows 计算机(XP、Vista 32/64、Win7 32/64)上有近 1000 个安装,到目前为止没有问题。

\n\n

似乎只有一台在 Win7 32 PC 上出现问题。

\n\n

任务管理器概述取决于当前活动:

\n\n

1 - 活动:程序启动

\n\n

https://i.stack.imgur.com/jA6j7.gif(见图)

\n\n

2 - 活动:简单地单击菜单项、按钮等

\n\n

https://i.stack.imgur.com/e0erH.gif(见图)

\n\n

对象 USER对象 GDI运行到 10\'000 并且应用程序抛出以下异常:

\n\n
System.ComponentModel.Win32Exception The current process has used all of its system allowance of handles for Window Manager objects \n\n\xc3\xa0 MS.Win32.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)\n   \xc3\xa0 MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)\n   \xc3\xa0 System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)\n   \xc3\xa0 System.Windows.Interop.HwndSource..ctor(HwndSourceParameters parameters)\n   \xc3\xa0 System.Windows.Window.SetTaskbarStatus()\n   \xc3\xa0 System.Windows.Window.CreateAllStyle()\n   \xc3\xa0 System.Windows.Window.CreateSourceWindowImpl()\n   \xc3\xa0 System.Windows.Window.SafeCreateWindow()\n   \xc3\xa0 System.Windows.Window.ShowHelper(Object booleanBox)\n   \xc3\xa0 System.Windows.Window.Show()\n   \xc3\xa0 System.Windows.Window.ShowDialog()\n   \xc3\xa0 WPFControls.WPFMessageBox.Show(String title, String message, String details, WPFMessageBoxButtons buttonOption, WPFMessageBoxImage image)\n   \xc3\xa0 MyApp.Prolog.Application_DispatcherUnhandledException(Object sender, DispatcherUnhandledExceptionEventArgs e)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.CatchException(Exception e)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.CatchExceptionStatic(Object source, Exception e)\n   \xc3\xa0 System.Windows.Threading.ExceptionWrapper.CatchException(Object source, Exception e, Delegate catchHandler)\n   \xc3\xa0 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)\n   \xc3\xa0 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)\n   \xc3\xa0 MS.Win32.UnsafeNativeMethods.SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags)\n   \xc3\xa0 System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)\n   \xc3\xa0 System.Windows.Window.CreateSourceWindowImpl()\n   \xc3\xa0 System.Windows.Window.SafeCreateWindow()\n   \xc3\xa0 System.Windows.Window.ShowHelper(Object booleanBox)\n   \xc3\xa0 System.Windows.Window.Show()\n   \xc3\xa0 System.Windows.Window.ShowDialog()\n   \xc3\xa0 WPFControls.WPFMessageBox.Show(String title, String message, String details, WPFMessageBoxButtons buttonOption, WPFMessageBoxImage image)\n   \xc3\xa0 MyApp.Prolog.Application_DispatcherUnhandledException(Object sender, DispatcherUnhandledExceptionEventArgs e)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.CatchException(Exception e)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.CatchExceptionStatic(Object source, Exception e)\n   \xc3\xa0 System.Windows.Threading.ExceptionWrapper.CatchException(Object source, Exception e, Delegate catchHandler)\n   \xc3\xa0 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)\n   \xc3\xa0 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)\n   \xc3\xa0 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)\n   \xc3\xa0 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)\n   \xc3\xa0 System.Windows.Window.ShowHelper(Object booleanBox)\n   \xc3\xa0 System.Windows.Window.Show()\n   \xc3\xa0 System.Windows.Window.ShowDialog()\n   \xc3\xa0 MyApp.Prolog.Prolog_Startup(Object sender, StartupEventArgs e) 0 0 0\n
Run Code Online (Sandbox Code Playgroud)\n\n

请问有人可以帮忙吗?

\n\n
\n\n

更新-编辑

\n\n

我们的客户确实安装了一个新的干净的(正如他所说的)Win 7 64 操作系统,但问题仍然存在。\n使用 WPF 应用程序似乎无法正常工作。

\n\n

我还尝试在客户计算机上使用 John Smith 编写的本文 (msdn.microsoft.com/de-de/magazine/dd419663.aspx) 的 MVVM 演示应用程序。

\n\n

当我尝试单击菜单项、按钮或在下拉列表中选择某些内容时,MVVM 演示应用程序也会崩溃。在文本字段中输入文本是可以的,但单击并选择确实会停止 MVVM 演示应用程序,并出现应用程序无法运行的错误。

\n\n

这是我的应用程序的事件日志

\n\n
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">\n    - <System>\n        <Provider Name="Application Error" />\n        <EventID Qualifiers="0">1000</EventID>\n        <Level>2</Level>\n        <Task>100</Task>\n        <Keywords>0x80000000000000</Keywords>\n        <TimeCreated SystemTime="2013-02-07T11:04:13.000000000Z" />\n        <EventRecordID>2243</EventRecordID>\n        <Channel>Application</Channel>\n        <Computer>RSSec.Machine.local</Computer>\n        <Security />\n    </System>\n    - <EventData>\n        <Data>MyApp.exe</Data>\n        <Data>2.0.16.0</Data>\n        <Data>51136bd8</Data>\n        <Data>unknown</Data>\n        <Data>0.0.0.0</Data>\n        <Data>00000000</Data>\n        <Data>c000041d</Data>\n        <Data>74494f0d</Data>\n        <Data>ecc</Data>\n        <Data>01ce0522d9d3bc67</Data>\n        <Data>C:\\Program Files (x86)\\MyApp\\MyApp.exe</Data>\n        <Data>unknown</Data>\n        <Data>1ad6d91f-7116-11e2-87c7-10604b689bfe</Data>\n    </EventData>\n</Event>\n
Run Code Online (Sandbox Code Playgroud)\n\n

有人可以再次帮忙吗?\nThx

\n

Han*_*ant 5

从堆栈跟踪中可以明显看出您的代码中至少存在一个问题。您已为 Dispatcher.UnhandledException 事件编写了一个事件处理程序,并使用消息框显示异常。如果此消息框已显示,您不必做的是确保避免执行此操作。通过跟踪中多次出现 MyApp.Prolog.Application_DispatcherUnhandledException() 可以看出。

因此,用户可能会看到充满一万个消息框的屏幕。此后,Windows 拒绝允许您的程序创建更多内容,从而拔掉了插头。

你还不知道真正的异常是什么样的。但这可能是一些恶心的事情,当调度程序循环运行时会一遍又一遍地抛出异常。您需要改进未处理的异常处理以获得崩溃的真正原因。 添加一个 bool 标志来指示显示消息框,并在该标志设置为 true 的情况下再次引发 UnhandledException 时终止程序。并记录异常,以便您可以找出抛出的内容,而无需用户读回消息框所说的内容。