A
Armin Zingler
Hello group, (VB 2003, Framework 1.1)
when Application.DoEvents is called in a second UI thread, it is not
possible to close the Form when Application.DoEvents is used. It's simple to
reproduce:
1. Create a new WindowsApplication and add two Buttons to the Form.
2. Add this code to the Form:
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim t As New Threading.Thread(AddressOf ThreadStart)
t.Start()
t.Join()
End Sub
Private Sub ThreadStart()
Dim f As New Form1
f.ShowDialog()
End Sub
Private Sub Button2_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click
Do
Application.DoEvents()
Loop While Me.IsHandleCreated
End Sub
3. Start
4. Click Button1 to show the second Form in the second thread.
5. Click Button2 on the second form to start the loop.
6. Try to close the Form using the X in the top-right of the Form
problem #1: The first time trying to click the X behaves as if clicking
button2 again. I consider it to be a bug.
problem #2: The Form can not be closed. My question is: Why? The loop is not
the problem. Restart the application, do *not* show the second for, but only
click button2. Now the form can be closed. Why not if the code is running in
a different thread? Everything else works in the second thread.
when Application.DoEvents is called in a second UI thread, it is not
possible to close the Form when Application.DoEvents is used. It's simple to
reproduce:
1. Create a new WindowsApplication and add two Buttons to the Form.
2. Add this code to the Form:
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim t As New Threading.Thread(AddressOf ThreadStart)
t.Start()
t.Join()
End Sub
Private Sub ThreadStart()
Dim f As New Form1
f.ShowDialog()
End Sub
Private Sub Button2_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click
Do
Application.DoEvents()
Loop While Me.IsHandleCreated
End Sub
3. Start
4. Click Button1 to show the second Form in the second thread.
5. Click Button2 on the second form to start the loop.
6. Try to close the Form using the X in the top-right of the Form
problem #1: The first time trying to click the X behaves as if clicking
button2 again. I consider it to be a bug.
problem #2: The Form can not be closed. My question is: Why? The loop is not
the problem. Restart the application, do *not* show the second for, but only
click button2. Now the form can be closed. Why not if the code is running in
a different thread? Everything else works in the second thread.