What do you do if you want to have a singleton form,
which isn't the main form? e.g. an Options dialog.
good posting. The article at 'sadeveloper' is a good one
- makes a good point about the threading aspects. I am
not sure about using the 'sealed', since GoF does
specify (if I recall correctly) that one can make it
extensible with subclassing.
Johnny: This should work for any form.
I'm with you, I had a play. Ignore my stupidity. I was
assuming something from the line:
Application.Run(Form1.Instance)
So I just use OptionsForm.Instance from wherever I want.
Thanks to all... so what's the better way? I think Roy
solutions could be good...
Your second criteria can be a tricky one. I'd agree that
in most implementations, what people mean by
"Singleton" is one and only one object
that never gets destroyed. However, in other systems,
"Singleton" just means "at
most one", and not necessarily that it won't be
destroyed. .NET Remoting is one example. If you use the
"Singleton" activation mode for a
server activated component, you get "at most
one" but not necessarily the same object, and
sometimes that might be appropriate.
Sorry, I realize that's not really relevant to WinForms
in particular, just a general comment.