Control.Invoke & Dialog Forms

R

Ryan

Hello everyone.

This is something that I can't for the life of me figure
out. When using a control's invoke method from a form
that is being called with showdialog, the invoke method
sits and waits until the form is closed down, where if
the form's parent calls a form.show method it the child
control's invoke method fires right away. Does anyone
know how to make the thread that the controls are on
continue to execute? Below I have some sample code in
VB.NET.





Public Class frmParent
Inherits System.Windows.Forms.Form
Friend WithEvents Button2 As
System.Windows.Forms.Button
Friend WithEvents Button1 As
System.Windows.Forms.Button

'Initialization here - I removed it make this shorter


Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim frm As Form1 = New Form1
frm.Show()
End Sub

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Dim frm As Form1 = New Form1
frm.ShowDialog()
End Sub
End Class


Public Class frmDialog
Inherits System.Windows.Forms.Form

'Initialization here - I removed it make this shorter


Public Sub Populate()
Me.Button2.Invoke(New EventHandler(AddressOf
ButtonInvoke))
End Sub
Private Sub ButtonInvoke(ByVal sender As Object,
ByVal args As EventArgs)
Me.Button2.Enabled = True
End Sub
Private mThread As System.Threading.Thread
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.mThread = New System.Threading.Thread
(AddressOf Me.Populate)
Me.mThread.Start()
End Sub
End Class
 
R

Ryan

Alex,

Which service pack is this for, Visual Studio 2003, or
is this for Windows CE?

Thanks Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top