I have created a simple window form(pasted below). Now I use this to display a wait dailog to the user when running a complex operation which consumes time.
Calling the HerculesWaitForm.Show("Some Title","Some Caption...)
shows the form as usual but when calling HerculesWaitForm.Close
still shows the form. What can I do to overcome the problem.
Imports System.Threading
Public Class HerculesWaitForm
Inherits DevExpress.Utils.WaitDialogForm
Private Shared form As HerculesWaitForm
Private Shared _thread As Thread
Private Shared _caption As String, _title As String
Private Sub New(ByVal caption As String, ByVal title As String)
MyBase.New(caption, title)
End Sub
Private Shared Sub CreateInstance()
form = New HerculesWaitForm(_caption, _title)
Application.Run(form)
Application.DoEvents()
End Sub
Public Overloads Shared Sub Show(ByVal caption As String, ByVal title As String)
_caption = caption
_title = title
If form Is Nothing Then
_thread = New Thread(AddressOf CreateInstance)
_thread.IsBackground = True
_thread.Start()
End If
End Sub
Public Overloads Shared Sub SetCaption(ByVal caption As String)
If form IsNot Nothing Then
_caption = caption
form.SetFormCaption()
Else
Show(caption, "")
End If
End Sub
Public Overloads Shared Sub Close()
If form IsNot Nothing Then
form.CloseForm()
form = Nothing
End If
End Sub
Private Sub CloseForm()
If Me.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf CloseForm))
Return
End If
Application.ExitThread()
End Sub
Private Sub SetFormCaption()
If Me.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf SetFormCaption))
Return
End If
MyBase.SetCaption(_caption)
End Sub
End Class