473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Singleton Form

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.

--
--Eric Cathell, MCSA
Nov 21 '05 #1
1 1965
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.

"ECathell" wrote:
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.

--
--Eric Cathell, MCSA

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mike | last post by:
Please help this is driving me nuts. I have 2 forms, 1 user class and I am trying to implement a singleton class. Form 1 should create a user object and populate some properties in user. Form2...
15
by: Mountain Bikn' Guy | last post by:
Is the second version shown below better? I couldn't locate enough info about in order to tell. 1.. My commonly used singleton pattern implementation looks like this (it was inspired by Eric...
8
by: Tony W | last post by:
Hi, I'm trying to write a small app where I need to keep referencing a stored file location that is stored in an xml file. My research suggests that I should use a Singleton to store the file...
4
by: a | last post by:
Hello Gang, I am in a bit of confusion regarding a half completed application I am writing. It is an MDI app, so I have a main form (frmMain) that is always open. I am looking for a 'Best...
0
by: Dennis | last post by:
I have a singleton class (a music player) then raises events. I originally dim an instance of this class in my main form using withevents and have event handlers for the singleton in this main...
35
by: Steve JORDI | last post by:
Hi, I'm trying to implement a singleton in PHP4 but it doesn't seem to work. The object is recreated each time I call it. The goal of the class is to keep a variable up to date. It's used to...
5
by: Damien | last post by:
Hi all, I'm using a pretty standard C++ Singleton class, as below: template <typename T> class Singleton { public: static T* Instance() {
8
by: giddy | last post by:
hi , Does a singleton statusbas controller sound correct. I mean , is that how its done? I have a big app and i need to control the statusbar from within a number of custom controls , dynamic...
2
by: Bob Johnson | last post by:
Just wondering the extent to which some of you are implementing classes as Singletons. I'm working on a brand new project and, early on, identified some obvious candidates. By "obvoius candidates"...
5
by: Lie | last post by:
This is probably unrelated to Python, as this is more about design pattern. I'm asking your comments about this design pattern that is similar in functionality to Singleton and Borg: to share...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.