9

We have a WPF app that need to stay opened for a longer period of time (overnight) with different users that log on and off to the respective PC.

[Update] The WPF app uses Single Instance technique from here: http://blogs.microsoft.co.il/blogs/arik/SingleInstance.cs.txt The single instance feature is not a cause for the bug

There is a strange crash happening only in the following situation:

  1. OS is Windows 10

  2. The following sequence of user sign in / sign off must happen:

Account A is starting the app and logs off or locks the PC. Account B signs in during the night, works on the PC for a while and then logs off. Account A signs in again in the morning. The app runs but is the UI is frozen/minimized. When clicked/ tried to be resized, the following error occurs:

   System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
   at System.Windows.Media.Composition.DUCE.Channel.SyncFlush()
   at System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean enableRenderTarget, Nullable`1 channelSet)
   at System.Windows.Interop.HwndTarget.UpdateWindowPos(IntPtr lParam)
   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

I already reviewed these posts

I tried the suggestions from the above posts with no luck.

Also, I cannot reproduce the problem consistently. It seem that some time needs to pass between the logins so that the problem to appear.

Thanks for any suggestion that you may have.

Community
  • 1
  • 1
phazzy
  • 91
  • 1
  • 3
  • 1
    WPF when improperly used can experience such memory issues and you have to learn best practices from the Internet to make sure resources (especially binding related) are freed properly. It would be too broad to list the tips as an answer. You might also learn how to analyze out of memory crash dumps, and that would show where the leak comes from. – Lex Li Nov 01 '16 at 10:50
  • 1
    Not a lot to go on, but i would assume you are calling New on a number of GUI or heavy resources that are never properly cleared. What is the nature of the app? – Ben Steele Nov 01 '16 at 14:39
  • 2
    I don't think is memory leaked related. The crash occurs only when, after user A logs in again, clicks the app's window. I left the app opened for days and nothing happened (also memory usage did not increase). Only in case of the log-on log-off sequence and only on windows 10. The app is very lightweight on GUI resources. What I found is that if I hide the window and I restore it only when user A logs in again, then the crash doesn't happen anymore. I hope I make sense. – phazzy Nov 04 '16 at 08:23
  • 1
    We ruled out the single instance feature as being the cause of it (it happened also with the feature disabled) – phazzy Nov 08 '16 at 15:44
  • Did you solve this issue? My guess is that you faced a graphics driver problem. – l33t Mar 04 '19 at 15:07

3 Answers3

3

Seems this is known WPF bug: https://github.com/dotnet/wpf/issues/439 No solution yet on June 3, 2020.

hellobody
  • 430
  • 5
  • 15
2

System.OutOfMemoryException or System.Runtime.InteropServices.COMException in System.Windows.Media.Composition.DUCE.Channel.SyncFlush() are usually caused by GDI objects or User objects leaks.

You can monitor these leaks in Task Manager. Select "GDI objects" or "User objects" columns for this. If GDI objects count exceeds limit (10000 is default for windows) you get OutOfMemory exception in your application.

Check your application for leak of System.Drawing namespace object references, icon handles that you forgot to destroy, etc...

For more information see https://blogs.msdn.microsoft.com/dsui_team/2013/11/18/wpf-render-thread-failures/

Boogier
  • 609
  • 6
  • 24
1

If you are using PNG bitmap images in your app, try changing them to some other format such as BMP, GIF, or JPEG. The .NET framework passes PNG decoding to the video driver, and some drivers have signed/unsigned bugs which can make the request gigabytes of RAM to decode the image, causing out of memory errors.

Jeff
  • 11
  • 1