Win32Exception: operation completed successfully

The following code fails with the exception:

MyWindow wnd = new MyWindow(); wnd.Show(); //here an exception occurs 

The exception is rather strange, but as I understand it, its error in .net

 System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully at MS.Win32.UnsafeNativeMethods.GetDC(HandleRef hWnd) at System.Windows.Interop.HwndTarget..ctor(IntPtr hwnd) at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters) at System.Windows.Interop.HwndSource..ctor(HwndSourceParameters parameters) at System.Windows.Window.CreateSourceWindow(Boolean duringShow) at System.Windows.Window.CreateSourceWindowDuringShow() at System.Windows.Window.SafeCreateWindowDuringShow() at System.Windows.Window.ShowHelper(Object booleanBox) at System.Windows.Window.Show() 

The MyWindow object is a window with some vector graphics inside, but not too much. In addition, this happens when 10-20 MyWindow objects are already open and closed.

Decision. The reason was the leak of GDI objects. They created in my low level error code. Thus, the problem did not concern the MyWindow object.

+4
source share
2 answers

It does not bomb the winapi error code, the actual error code is E_FAIL, COM error code. Which is very useless for diagnosing anything, it does not mean anything more than "could not do this, I do not know why." How GetDC () can produce this error code is very hard to guess, I suspect this is due to the environment with something related to the winapi function. Perhaps something similar to a remote desktop or screen recorder. Try running this on another machine.

The β€œcommon” reason for GetDC () to fail is a handle leak. Windows stops giving the process more handles when it has already consumed 10,000 of them. Something you can diagnose with TaskMgr.exe, the Processes tab. View + Select Columns and tick Handles, USER Objects and GDI Objects. First check the list of processes and make sure that you do not have a process that consumes a lot of them. The total number of GDI objects for all processes in a session is limited by the size of the session pool. Then run your program and keep track of the values ​​for your process.

+8
source

We have this problem in our project ...

we pushed all view and view models onto the stack, and then show them one at a time. The solution was to show items one by one without making a stack.

0
source

Source: https://habr.com/ru/post/1385761/


All Articles