Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. System.OutOfMemory exception: error creating window handle

System.OutOfMemory exception: error creating window handle

Scheduled Pinned Locked Moved C#
csharpdebugginghelpquestionsharepoint
5 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Serge Lobko Lobanovsky
    wrote on last edited by
    #1

    Hi, Software: .NET 1.1 (both non-SP and SP1) Visual Studio .NET 2003 MS SQL Server 2000 SP3 Windows XP SP 2 Hardware: Intel Celeron 1700, Pentium 4 2.4GHz, AMD Athlon 1100 RAM 256-512 DDR I've run into a strange problem. There is an application which allows to: 1) connect to a certain device using a modem 2) manage different aspects (mostly, working with MS SQL Server) Serial communication is done on a separate thread, one per each connection. The maximum number of simultaneous connections is 20. Note: what is written below applies only when running the application not under the debugger. The app starts and works correctly: accepts incoming calls, performs different scenarios, dials out when necessary. When the comms thread needs to modify the UI, it is correctly done using Control.BeginInvoke. However, sometimes (on different computers) the following exception is thrown: System.OutOfMemory exception: error creating window handle ---> System.NullReferenceException: Object reference not set to an instance of object. at System.Windows.Forms.ThreadContext.OnThreadException at System.Windows.Forms.Control.WndProcException at System.Windows.Forms.ControlNativeWindow.OnThreadException at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr) at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(int32, string, string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef, object) at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int32, string, string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef, object) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams) -- End of inner exception stack trace -- at System.Windows.Forms.ThreadContext.OnThreadException at System.Windows.Forms.Control.WndProcException at System.Windows.Forms.ControlNativeWindow.OnThreadException at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef, int32) at System.Windows.Forms.Control.SetVisibleCore at System.Windows.Forms.Form.SetVisibleCore at System.Windows.Forms.Control.set_Visible at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) at System.Windows.Forms.Form.ShowDialog at What could be the problem? Let me stress that this does not happen under debuggers. When debugging, the exception is not thrown. It was noted that this happens more often when having an active connection. Regards, Serge (Logic Sof

    H A 2 Replies Last reply
    0
    • S Serge Lobko Lobanovsky

      Hi, Software: .NET 1.1 (both non-SP and SP1) Visual Studio .NET 2003 MS SQL Server 2000 SP3 Windows XP SP 2 Hardware: Intel Celeron 1700, Pentium 4 2.4GHz, AMD Athlon 1100 RAM 256-512 DDR I've run into a strange problem. There is an application which allows to: 1) connect to a certain device using a modem 2) manage different aspects (mostly, working with MS SQL Server) Serial communication is done on a separate thread, one per each connection. The maximum number of simultaneous connections is 20. Note: what is written below applies only when running the application not under the debugger. The app starts and works correctly: accepts incoming calls, performs different scenarios, dials out when necessary. When the comms thread needs to modify the UI, it is correctly done using Control.BeginInvoke. However, sometimes (on different computers) the following exception is thrown: System.OutOfMemory exception: error creating window handle ---> System.NullReferenceException: Object reference not set to an instance of object. at System.Windows.Forms.ThreadContext.OnThreadException at System.Windows.Forms.Control.WndProcException at System.Windows.Forms.ControlNativeWindow.OnThreadException at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr) at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(int32, string, string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef, object) at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int32, string, string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef, object) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams) -- End of inner exception stack trace -- at System.Windows.Forms.ThreadContext.OnThreadException at System.Windows.Forms.Control.WndProcException at System.Windows.Forms.ControlNativeWindow.OnThreadException at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef, int32) at System.Windows.Forms.Control.SetVisibleCore at System.Windows.Forms.Form.SetVisibleCore at System.Windows.Forms.Control.set_Visible at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) at System.Windows.Forms.Form.ShowDialog at What could be the problem? Let me stress that this does not happen under debuggers. When debugging, the exception is not thrown. It was noted that this happens more often when having an active connection. Regards, Serge (Logic Sof

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      I see from your stacktrace that you're using ShowDialog. When using modal dialogs, you need to make sure you dispose your forms or you will lose memory quickly. This isn't always a problem running under a debugger because the GC hasmore time to clean-up resources. When displaying modal dialogs using ShowDialog, it's best to use the using block statement as below:

      using (MyForm form = new MyForm())
      {
      form.ShowDialog();
      }

      This compiles to something similar to this:

      MyForm form = null;
      try
      {
      form = new MyForm();
      form.ShowDialog();
      }
      finally
      {
      if (form != null) ((IDisposable)form).Dispose();
      }

      This way - even if an exception is thrown - the form's resources (i.e., the message pump on the new thread and other native resources used by the controls, since the controls merely encapsulate native Common Controls and other windows, are freed-up. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      S 2 Replies Last reply
      0
      • H Heath Stewart

        I see from your stacktrace that you're using ShowDialog. When using modal dialogs, you need to make sure you dispose your forms or you will lose memory quickly. This isn't always a problem running under a debugger because the GC hasmore time to clean-up resources. When displaying modal dialogs using ShowDialog, it's best to use the using block statement as below:

        using (MyForm form = new MyForm())
        {
        form.ShowDialog();
        }

        This compiles to something similar to this:

        MyForm form = null;
        try
        {
        form = new MyForm();
        form.ShowDialog();
        }
        finally
        {
        if (form != null) ((IDisposable)form).Dispose();
        }

        This way - even if an exception is thrown - the form's resources (i.e., the message pump on the new thread and other native resources used by the controls, since the controls merely encapsulate native Common Controls and other windows, are freed-up. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        S Offline
        S Offline
        Serge Lobko Lobanovsky
        wrote on last edited by
        #3

        Thank you, Heath. I will implement this. Regards, Serge (Logic Software, Easy Projects .NET site)

        1 Reply Last reply
        0
        • H Heath Stewart

          I see from your stacktrace that you're using ShowDialog. When using modal dialogs, you need to make sure you dispose your forms or you will lose memory quickly. This isn't always a problem running under a debugger because the GC hasmore time to clean-up resources. When displaying modal dialogs using ShowDialog, it's best to use the using block statement as below:

          using (MyForm form = new MyForm())
          {
          form.ShowDialog();
          }

          This compiles to something similar to this:

          MyForm form = null;
          try
          {
          form = new MyForm();
          form.ShowDialog();
          }
          finally
          {
          if (form != null) ((IDisposable)form).Dispose();
          }

          This way - even if an exception is thrown - the form's resources (i.e., the message pump on the new thread and other native resources used by the controls, since the controls merely encapsulate native Common Controls and other windows, are freed-up. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

          S Offline
          S Offline
          Serge Lobko Lobanovsky
          wrote on last edited by
          #4

          I did implement the scheme you suggested, however I'm still having the same problems. Could you suggest anything else? Should I call GC.Collect() manually? Or any other ideas? Also, I put [STAThread] attribute as suggested to me at MSDN managed newsgroups, which also didn't help. Regards, Serge (Logic Software, Easy Projects .NET site)

          1 Reply Last reply
          0
          • S Serge Lobko Lobanovsky

            Hi, Software: .NET 1.1 (both non-SP and SP1) Visual Studio .NET 2003 MS SQL Server 2000 SP3 Windows XP SP 2 Hardware: Intel Celeron 1700, Pentium 4 2.4GHz, AMD Athlon 1100 RAM 256-512 DDR I've run into a strange problem. There is an application which allows to: 1) connect to a certain device using a modem 2) manage different aspects (mostly, working with MS SQL Server) Serial communication is done on a separate thread, one per each connection. The maximum number of simultaneous connections is 20. Note: what is written below applies only when running the application not under the debugger. The app starts and works correctly: accepts incoming calls, performs different scenarios, dials out when necessary. When the comms thread needs to modify the UI, it is correctly done using Control.BeginInvoke. However, sometimes (on different computers) the following exception is thrown: System.OutOfMemory exception: error creating window handle ---> System.NullReferenceException: Object reference not set to an instance of object. at System.Windows.Forms.ThreadContext.OnThreadException at System.Windows.Forms.Control.WndProcException at System.Windows.Forms.ControlNativeWindow.OnThreadException at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr) at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(int32, string, string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef, object) at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int32, string, string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef, object) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams) -- End of inner exception stack trace -- at System.Windows.Forms.ThreadContext.OnThreadException at System.Windows.Forms.Control.WndProcException at System.Windows.Forms.ControlNativeWindow.OnThreadException at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef, int32) at System.Windows.Forms.Control.SetVisibleCore at System.Windows.Forms.Form.SetVisibleCore at System.Windows.Forms.Control.set_Visible at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) at System.Windows.Forms.Form.ShowDialog at What could be the problem? Let me stress that this does not happen under debuggers. When debugging, the exception is not thrown. It was noted that this happens more often when having an active connection. Regards, Serge (Logic Sof

            A Offline
            A Offline
            ave kevinchen
            wrote on last edited by
            #5

            I also met this problem days ago and finally found I set the value for a variable in wrong section(Notice the innerException). I set it in Form_Load(), and everything goes well when I move it to constructor. May this helps.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups