need help with showdialog within another thread

dstrough

New member
Joined
Aug 21, 2009
Messages
3
Programming Experience
1-3
Hey all,

Thanks for taking the time to read this.

I am having an issue where I am starting another thread which opens a form. Succinctly, it is an animated "Please wait.. processing" type of form. The issue is that I want to make this form a child form of the parent (main thread or main GUI) when I open it.

The issue is that I prefer to use frmProcessing.ShowDialog(frmMain) instead of just frmProcessing.Show, because of form disappearing issues. It, of course, gives me an error of illegal cross thread operation. My question is, how do I perform frmProcessing.ShowDialog(frmMain) to show from within another thread, that the newly opened form is actually a child of the main thread. Is there a better way for me to make a small processing form telling the user to be patient while background processes are working?

Thank you for any help you can give me. The code is below.


SQL.vb
VB.NET:
        frmMain.processing = New Threading.Thread(AddressOf frmMain.processingForm)
        Dim processingInfo(1) As String
        processingInfo(0) = "Loading SQL instances..."
        frmMain.processing.IsBackground = True
        frmMain.processing.Start(processingInfo)


        Do Stuff...


        frmMain.processing.Abort

frmMain.processingForm
VB.NET:
    Public Sub processingForm(ByVal processingInfo() As String)
        If frmProcessing.Visible = False Then
            frmProcessing.ShowDialog()
        End If

        frmProcessing.Label1.Text = processingInfo(0)

        Do
            frmProcessing.Refresh()
            Application.DoEvents()
        Loop
    End Sub
 
You can use Control.Invoke to call any method on that controls thread. You need to use a delegate instance pointing to (AddressOf) that method, and the delegate need to have same signature as the method called.
 
Back
Top