is Disposed required for shared form ??

  • Thread starter Thread starter Stoitcho Goutsev \(100\) [C# MVP]
  • Start date Start date
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Alok,

If you dispose the form you have to created again next time some part of the
code needs to show the form. It somehow defeats the purpose of the singleton
design pattern.

Be aware that if you dispose a form and check the reference to the form for
null it will fail. You have to chack the reference fo IsDisposed and if it
is to created new instance of the form class. There is no public method to
recreate a control after it's been disposed.

I'm don't know your program but I think you shouldn't dispose the form.
 
Hi,
I have a Windows App which uses a custom form to display messages.
This form is based on the singleton pattern so that the user does not need
to explicitly create an object of this form.

After the Showdialog() method on this form, do i need to dispose this form
explicitly. i distinctly remember one article saying that all Modal forms
needs to be disposed explicitly.

This is the code snippet i am using:

Public Class myMessageForm
Private Sub New()
'new instance not possible
End Sub

private Shared frmMsg as MyMessageForm = Nothing

Public Shared Function Display(ByVal text as String) as DialogResult
If frmMsg is nothing then
frmMsg = New MyMessageForm
End If
'Set some properties

Return frmMsg.ShowDialog()
End Function

Calling Code:
If txtCustId.text.Length = 0 Then
MyMessageForm.Display("Invalid Customer Id")
End If

Any help would be appreciated.

TIA :)
 
Back
Top