Messagebox.Show hangs execution

G

Guest

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.Suspen
05 e.Cancel = MessageBox.Show(strQuitMessage, strQuitTitle,
MessageboxButtons.OKCancel) = DialogResult.Cance
06 mvarEngineThread.Resum
07 'Thread is terminated in _Closed even
08 End Su

I set the cancelButton property of the MDI child to close the child using ESC

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

Instead of posting my actual thread processing code, I can replicate the problem using the following

Public Sub ThreadProc(
D
For i As Integer = 0 To 100
Dim a As New System.Text.StringBuilder(400
Nex
System.Threading.Thread.Sleep(0
Loo
End Su
 
L

Lifeng Lu

I don't know why you should call Thread.Suspend there. After you suspended
the thread, of course it will hang up and will never run to the next line
(where you call MessageBox.Show). How can you hope the thread resume itself?

One thing to remeber is the green line often pointing to the next line of
code, but not where the real problem is.

Your second piece of code is aparently dead loop.

Thanks
MS VB
 

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