A
Aaron
Hi,
1. Can a seperate thread create a form?
I created some test code. I have a sub Test that attempts to create
and show a form, objFrmTest which is of type frmTest. Button1 and
Button2 exist on another form (not frmTest). Button1 attempts to run
sub Test with another thread, which Button2 simply attempts to run sub
Test. The results, in short, are the Button1 does not work while
Button2 does. Also, once Button1 is run, neither will work properly
there after.
I setup some breakpoints and did found that in both cases, the creating
thread sucessfully ran both the form constructor and the Load event.
In spite of that though, Button1 cannot bring up frmTest.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim thdTest As Thread
thdTest = New Thread(AddressOf Test)
thdTest.Name = "ThreadTest"
thdTest.Priority = ThreadPriority.Highest
thdTest.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Test()
End Sub
Public Sub Test()
If objFrmDiscrepancy Is Nothing Then
objFrmDiscrepancy = New frmDiscrepancy
ElseIf objFrmDiscrepancy.IsDisposed Then
objFrmDiscrepancy = Nothing
objFrmDiscrepancy = New frmDiscrepancy
End If
objFrmDiscrepancy.Show()
objFrmDiscrepancy.WindowState = FormWindowState.Normal
End Sub
2. Assuming that a thread can create a form, will all the event
handlers on the form execute against the primary thread (default
thread? application thread?) or the thread that created it?
3. Can a form be configured such that the user cannot click on any
other forms within the application without first closing said form
(Similar to a message box), w/ or w/o multithreading?
Thanks,
Aaron
1. Can a seperate thread create a form?
I created some test code. I have a sub Test that attempts to create
and show a form, objFrmTest which is of type frmTest. Button1 and
Button2 exist on another form (not frmTest). Button1 attempts to run
sub Test with another thread, which Button2 simply attempts to run sub
Test. The results, in short, are the Button1 does not work while
Button2 does. Also, once Button1 is run, neither will work properly
there after.
I setup some breakpoints and did found that in both cases, the creating
thread sucessfully ran both the form constructor and the Load event.
In spite of that though, Button1 cannot bring up frmTest.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim thdTest As Thread
thdTest = New Thread(AddressOf Test)
thdTest.Name = "ThreadTest"
thdTest.Priority = ThreadPriority.Highest
thdTest.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Test()
End Sub
Public Sub Test()
If objFrmDiscrepancy Is Nothing Then
objFrmDiscrepancy = New frmDiscrepancy
ElseIf objFrmDiscrepancy.IsDisposed Then
objFrmDiscrepancy = Nothing
objFrmDiscrepancy = New frmDiscrepancy
End If
objFrmDiscrepancy.Show()
objFrmDiscrepancy.WindowState = FormWindowState.Normal
End Sub
2. Assuming that a thread can create a form, will all the event
handlers on the form execute against the primary thread (default
thread? application thread?) or the thread that created it?
3. Can a form be configured such that the user cannot click on any
other forms within the application without first closing said form
(Similar to a message box), w/ or w/o multithreading?
Thanks,
Aaron