Question : how to trap this exception?

Everytime I close my program, I receive the error as shown in the attached image.

The error pops up after the program reaches the end sub in the sub main.

Any ideas?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Sub Main()
        Application.EnableVisualStyles()
        Dim bTesting As Boolean = IsRegister()
        Dim bEnterprise As Boolean = False
        MySolutions.Utils.SetData("BetaVersion", Not bTesting)
        MySolutions.Utils.SetData("Enterprise", bEnterprise)
        MySolutions.Utils.SetData("Version", "2.235")
        MySolutions.Utils.SetData("DBVersion", 2.22)

        MySolutions.Utils.SetData("UserID", -1)
        Dim coZK As New ZKCoClass.ZKCoClass
        coZK.ZKObject = New zkemkeeper.CZKEMClass
        TABase.TAUtils.ZKObject = coZK
        Dim frm As New Form1
        If frm.Initialize() = True Then
            Application.Run(frm)
        End If

    End Sub

Answer : how to trap this exception?

Hello,

The error you are seeing is almost always going to display when  there has been a memory-allocation mismanagement of some kind. How to track it down? This is rather challenging.

In your case the problem is not evident from the code you provided. The problem is your line of code:

   Application.Run(frm)

At that point forward, we have lost visibility of everything your program is doing or is trying to do.

My first suggestion is to keep your code exactly as-is and in your frm's Main sub, just comment-out EVERYTHING then add this line:

   System.Windows.Forms.Application.Exit()

Then see if you still get the error. If you don't, the problem is likely in the code the you had removed from
frm Main or something that ran after the frm was loaded and running. Otherwise, you might benefit from reading more here:

   http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx

and

   http://vbcity.com/forums/p/96612/406742.aspx

Regards,
Jon

Random Solutions  
 
programming4us programming4us