[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Windows Forms Throwing a system.OutOfMemoryException Additional information: Error creating window handle

Posted on 2006-05-23
15
Medium Priority
?
2,053 Views
Last Modified: 2012-05-05
I am having a problem that I haven't had before and I don't understand where it's comming from.

I have a child form called frmUse that has a button click event that calls objfrmPeople.show  This was working fine until just recently while I have been attempting to seperate the DB access into a seperate tier.  Now I am getting the error:

   An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll

   Additional information: Error creating window handle.

I am concerned that it may be somehow related to the Windows Forms Generated Code region since I was mucking around there while I was trying to set the form's databindings to a seperate tier. Below is the stack trace for the error.  I will be happy to post code but don't know what to post yet any direction will be appreciated.

I traped the error to get the stack trace:

   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Form.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.Control.Show()
   at Foundation.frmUse.btnPeople_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator.CHEYENNE\My Documents\Visual Studio Projects\Foundation\frmUse.vb:line 102
0
Comment
Question by:Bull_81073
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 5

Expert Comment

by:mydasx
ID: 16747146
show us the code please both your calling code and the behind the scenes code for the form.
0
 
LVL 2

Expert Comment

by:anwar ul haque
ID: 16749082
Hi
try to dispose the objects properly and increase your RAM if possible.
0
 
LVL 2

Author Comment

by:Bull_81073
ID: 16756051
---Code creating my form and com objects---

Module SubMain
    Public objfrmMain As frmMain
    Public objfrmUse As frmUse
    Public objfrmpeople As frmPeople
    Public objcomFound As comFound
    Public objfrmAddress As frmAddress
    Public objfrmNewAddress As frmNewAddress

    Public Sub Main()
        objcomFound = New comFound
        objcomFound.daState.Fill(objcomFound.DsFound1, "state")
        objcomFound.daAddress.Fill(objcomFound.DsFound1, "address")
        objcomFound.daPerson.Fill(objcomFound.DsFound1, "person")
        objcomFound.daSex.Fill(objcomFound.DsFound1, "sex")
        objfrmMain = New frmMain
        objfrmMain.ShowDialog()
    End Sub

----Button Click Event to Display The Form---
    Private Sub btnPeople_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPeople.Click
        objfrmpeople = New frmPeople
        objfrmpeople.MdiParent = objfrmMain
        objfrmpeople.StartPosition = FormStartPosition.CenterParent
        objfrmpeople.lblID.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.Person_ID"))
        objfrmpeople.txtFName.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.First_Name"))
        objfrmpeople.txtLName.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.Last_Name"))
        objfrmpeople.cmbSex.DataSource = objcomFound.DsFound1.Sex
        objfrmpeople.cmbSex.DisplayMember = "sexVal"
        objfrmpeople.cmbSex.ValueMember = "sexID"
        objfrmpeople.chkMail.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Current_Mail"))
        objfrmpeople.chkDead.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Deceased"))
        objfrmpeople.lblAdd.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Address.Address_ID"))
        objfrmpeople.chkMarried.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Married"))
        objfrmpeople.txtMaiden.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.Maiden_Name"))
        objfrmpeople.chk100.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Donations_100"))
        objfrmpeople.chkPlaque.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Plaque"))

        Try
            objfrmpeople.Show()  '<------- This is where the error is being thrown
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine(ex.Source & ControlChars.NewLine & ControlChars.NewLine & ex.Message & ControlChars.NewLine & ControlChars.NewLine & ex.StackTrace)
        End Try
    End Sub

----Below is the Form_Load Sub for the form I can't display----

    Private Sub frmPeople_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        bmFound = Me.BindingContext(objcomFound.DsFound1, "person")
        bmAddress = Me.BindingContext(objcomFound.DsFound1, "address")
        AddHandler bmFound.PositionChanged, AddressOf Position_Changed

        Position_Changed(sender, e)
        lockBoxes()

    End Sub


I will post the Windows Form Designer generated code in another post if you need to see it  (Its about 800 lines)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Bull_81073
ID: 16756063
I didn't think that I needed to dispose of the objects anymore, I was under the impression that .NET took care of that for you.

I am developing on a Zeon based machine with 1.5 GB RAM I don't think that's the problem.
0
 
LVL 2

Expert Comment

by:anwar ul haque
ID: 16758196
what i know about this exception...if your application is experiencing any unhandled exception while it is being desposed it will throw 'out of memory exception' that's why I told you to properly despose your objects as this has always been a good programming practice. always use try/catch block while you are accessing any external resource or file or database. and write the exception results into log file ..it will help you to trace the problem and secondly this will protect your application from being  crashed or halted...
0
 
LVL 2

Expert Comment

by:anwar ul haque
ID: 16758215
put these lines in try catch block and debug the application ...designer code itself can not throw out of memory exception...mind it :)

    objcomFound = New comFound
        objcomFound.daState.Fill(objcomFound.DsFound1, "state")
        objcomFound.daAddress.Fill(objcomFound.DsFound1, "address")
        objcomFound.daPerson.Fill(objcomFound.DsFound1, "person")
        objcomFound.daSex.Fill(objcomFound.DsFound1, "sex")
0
 
LVL 5

Expert Comment

by:mydasx
ID: 16762167
is this the MDA error?
0
 
LVL 2

Author Comment

by:Bull_81073
ID: 16763857
Sorry I am not familiar with MDA
0
 
LVL 2

Author Comment

by:Bull_81073
ID: 16763908
I have tried the try catch with the dataAdapter fills but it still doesn't help
0
 
LVL 2

Expert Comment

by:anwar ul haque
ID: 16766601
Are you working with with .Net framework 1.1 ? If so try to install .net framework hotfix 1.1. tell me if you have already installed, otherwise you can run windows update and install hotfix.
You can download it from this location...
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=A8F5654F-088E-40B2-BBDB-A83353618B38
0
 
LVL 2

Author Comment

by:Bull_81073
ID: 16770190
I have the 2.0.50727 dotnetframework installed
0
 
LVL 2

Expert Comment

by:anwar ul haque
ID: 16776133
even then you need hotfix from microsoft..best luck :)
0
 
LVL 2

Author Comment

by:Bull_81073
ID: 16802518
I have solved the problem myself!

So you all know!

The problem was that I when I made the change to a seperated data tier (in objcomFound) I forgot to add the objcomfound. in front of the dataset name in the BindingManager Position_Changed sub.  Now I have forgotten to do thins in the past but it never gave me this error.  Strange to say the least.  I can only imagine that the error was exposing itself this way because of the way that the Position_Changed sub is called.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 16991531
PAQed with points refunded (205)

DarthMod
Community Support Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question