Armin,
Your code looks very similiar to my test code (VB 2003). The only difference I can see is the threading procedure:
Public Sub ThreadProc()
Do
For i As Integer = 0 To 1000
Dim a As New System.Text.StringBuilder(400)
Next
System.Threading.Thread.Sleep(0)
Loop
End Sub
----- Armin Zingler wrote: -----
"Pi" <an*******@discussions.microsoft.com> schrieb
I have an MDI parent with one or more children forms. Each child
form has an engine thread that processes data. The child form's
_Closing event is roughly: 01 Private Sub frmConvertable_Closing(sender, e)
02 'Show the form (other MDI children may be on top)
03 Me.Activate()
04 mvarEngineThread.Suspend
05 e.Cancel = MessageBox.Show(strQuitMessage, strQuitTitle, _
MessageboxButtons.OKCancel) =
DialogResult.Cancel
06 mvarEngineThread.Resume
07 'Thread is terminated in _Closed event
08 End Sub When I run the application and hold down Esc to continually call the
closing event and cancel the messagebox (resume processing), after a
few seconds the application hangs. Breaking into the debugger shows
that line 05 is highlighted green. If I comment out the mvarEngineThread suspend and resume (lines 04
and 06) the application never hangs when I hold down Esc. Can anybody offer an explaination for this?
Did you set the cancelbutton property of the MDI child to close the child
using ESC? That's what I assumed to test the situation. I could not
reproduce the problem (VB 2003). I held down ESC several seconds.
This is my code in the child window:
Dim t As Threading.Thread
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
t = New Threading.Thread(AddressOf threadstart)
t.Start()
End Sub
Private Sub threadstart()
Do
Threading.Thread.Sleep(100)
Loop
End Sub
Private Sub Form2_Closing( _
ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
2: 'Show the form (other MDI children may be on top)
3: Me.Activate()
4: t.Suspend()
5: e.Cancel = MessageBox.Show("", "", _
MessageBoxButtons.OKCancel) = DialogResult.Cancel
6: t.Resume()
7: 'Thread is terminated in _Closed event
End Sub
Private Sub Form2_Closed( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Closed
t.Abort()
End Sub
Private Sub Button2_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
After opening the child, I clicked button1 to start the thread, then held
down Esc.
--
Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html