Form Show on Safe Thread

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Visual Basic:
    Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
        'Thread
        Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf myThread))
        Threads.Start()
    End Sub

    Private Sub myThread(ByVal o As Object)
        Dim F As New Form1
        F.ShowDialog()
    End Sub
Hi,
In my code, when I try to show a form in a safe thread as modal, I cannot, the form won't be modal, what can I do?
I need your help.
Thank you:)
 
It looks as though you are getting a second message pump for the dialog box - effectively the dialog is being modal on it's own windows message pump.

Is there a reason you need the dialog to have it's own thread?
 
It looks as though you are getting a second message pump for the dialog box - effectively the dialog is being modal on it's own windows message pump.

Is there a reason you need the dialog to have it's own thread?

That it just a sample, you think it is:
Visual Basic:
Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
'Thread
Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf myThread))
Threads.Start()
End Sub

Private Sub myThread(ByVal o As Object)
Dim F As New AnotherForm
F.ShowDialog()
End Sub
 
In order for the form to be shown modally, it should be shown via the main thread. If the second thread needs to wait for the form to be closed, it should block until the main thread can signal that the form has been closed. As for the precise mechanics required, you would have to consult some reference, a tutorial, or someone who knows more about multithreading than I.
 
Visual Basic:
    Private Delegate Sub MyFormHandler()
    Private Sub ShowMyForm()
        If Me.InvokeRequired Then
            Dim d As New MyFormHandler(AddressOf ShowMyForm)
            Me.Invoke(d)
        Else
            Dim F As New MyFormForm
            F.ShowDialog()
        End If
    End Sub
Visual Basic:
Me.ShowMyForm()
 
Back
Top