Singleton Form

E

ECathell

I have a windows form that I only want one instance of. it currently is a child mdi form which may be changing as the project progresses. I have made it a singleton object by making the Sub new constructor private then using this code to call it:

Private Shared m_instance As ShippingOrderSetupInterface

Public Shared Function getInstance() As ShippingOrderSetupInterface
If m_instance Is Nothing Then
m_instance = New ShippingOrderSetupInterface
End If
m_instance.WindowState = FormWindowState.Maximized
Return m_instance

End Function

It works great. However, when I close the window, then try and reopen it later, i get an disposed object exception. How do I get around this? I have tried adding me.dispose after me.close. If I simply hide the window, it will work I suppose, but I am curious about the proper way to do it.
 
G

Guest

I may be wrong but I believe that is the purpose of the .Hide method! What's
wrong with that? Once you close a form, it is disposed and that instance is
gone forever.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top