Peter,
Thank you for looking into this. I didn't realize it earlier but the
problem is related to threading. Here's the situation (and
reproducible code follows):
Form 1 does a show dialog which launces a threadpool operation which
broadcasts an event which form1 (yes, the original form) catches and
calls another showdialog.
I was told (and research didn't disprove, but couldn't confirm) that
the act of broadcasting an event also handled multi-threading and that
when you broadcast an event the call is made on the appropriate
thread, just like a Control.Invoke.
That appears to be the problem, 'cause if i change the event broadcast
to be a direct Control.Invoke, then the problem goes away. Of course
this isn't an option in the real application (too tight coupling) but
it can lead to a solution.
If there is another option or workaround or if there is something I'm
doing wrong, I'd appreciate the feedback. Also, if you or anyone has
links to documentation on how events are related to multi-threading
(to show my coworker that gave the apparently incorrect information),
that would be helpful.
Thanks,
Sam
Imports System.Threadin g
Imports System.Windows. Forms
Public Class ShowDialogTest
Public Shared Sub Main()
Application.Run (New Form1)
End Sub
End Class
Public Class Form1
Inherits Form
Private Shared _counter As Integer = 0
Public Sub New()
_counter += 1
Text = "Form " + _counter.ToStri ng()
AddHandler TriggerNew, AddressOf Form1_TriggerNe w
End Sub
Private Sub Form1_Click(ByV al sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Click
ThreadPool.Queu eUserWorkItem(A ddressOf TriggerStart)
End Sub
Public Event TriggerNew As EventHandler
Private Sub TriggerStart(By Val state As Object)
RaiseEvent TriggerNew(Me, EventArgs.Empty )
' if we change it to not use an event but use Invoke instead,
' then ShowDialog problem is fixed
'Invoke(New EventHandler(Ad dressOf Form1_TriggerNe w))
End Sub
Private Sub Form1_TriggerNe w(ByVal sender As Object, ByVal e As
EventArgs)
Dim f As New Form1
f.ShowDialog()
End Sub
End Class
On Thu, 27 Jan 2005 02:43:05 GMT,
v-******@online.m icrosoft.com
("Peter Huang" [MSFT]) wrote:
Hi
It seems that I can not reproduce the problem on my side.
Here is my reproduce code.
If I have any misunderstandin g, please feel free to post here.
[startup class]
Public Class Class1
Public Shared Sub Main()
Application.Run (New Form3)
End Sub
End Class
[Form3]
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click
Dim fm As New Form4
fm.ShowDialog()
End Sub
[Form4]
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click
Dim fm As New Form ' We note it as A
fm.ShowDialog()
End Sub
If we did not close A, neither Form4 nor Form3 can not activated.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.