簡単なウィンドウフォームを作成しました(以下に貼り付けます)。これを使用して、時間がかかる複雑な操作を実行しているときに、ユーザーに待機ダイログを表示します。
を呼び出すHerculesWaitForm.Show("Some Title","Some Caption...)
と通常どおりフォームが表示されますが、呼び出すとフォームがHerculesWaitForm.Close
表示されます。問題を克服するために私は何ができますか。
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