how to limit the number of winform objects to one
-
I have a winform application that opens other winform objects I need to limit these new winform objects to one instance. I understand mutexes but don't know what to override in the winform object to limit it to a single instance.
-
I have a winform application that opens other winform objects I need to limit these new winform objects to one instance. I understand mutexes but don't know what to override in the winform object to limit it to a single instance.
if it is all about forms in a single application, why can't you keep a count and organize things the way you want? I don't see the need for mutexes here. if it is about limiting the number of instances of a specific app, then that is where a mutex would come in. Search this site for "single instance application", you will find lots of articles (language doesn't matter, the principles are the same everywhere), some are good. BTW: none of them really limit the apps to one, all they do is have the extra instances close as soon as possible, however they do open first... :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
if it is all about forms in a single application, why can't you keep a count and organize things the way you want? I don't see the need for mutexes here. if it is about limiting the number of instances of a specific app, then that is where a mutex would come in. Search this site for "single instance application", you will find lots of articles (language doesn't matter, the principles are the same everywhere), some are good. BTW: none of them really limit the apps to one, all they do is have the extra instances close as soon as possible, however they do open first... :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Your right the mutex is over kill what I need to know is which method to override in order to close the child winform objects. I'm new to the dot net platform and still learning.
-
Your right the mutex is over kill what I need to know is which method to override in order to close the child winform objects. I'm new to the dot net platform and still learning.
I still sense some confusion. You can close a modeless form (that is one shown through
Show()
as opposed to a modal dialog, which gets shown by callingShowDialog()
) by calling itsClose()
method, no need to override anything. However, if you want to limit the number of open windows, why not just NOT open them, rather than closing them once you decided they are too many? :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I still sense some confusion. You can close a modeless form (that is one shown through
Show()
as opposed to a modal dialog, which gets shown by callingShowDialog()
) by calling itsClose()
method, no need to override anything. However, if you want to limit the number of open windows, why not just NOT open them, rather than closing them once you decided they are too many? :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Thanks for your help I didn't realize you could make a winform modal.
-
I have a winform application that opens other winform objects I need to limit these new winform objects to one instance. I understand mutexes but don't know what to override in the winform object to limit it to a single instance.
See my answer (Solution 2) to this question How to open only one instance of class not more[^]. It's exactly what you're looking for. Cheers!