RE: POPUp - VB.Net



Hi,

Thanks for the feedback! Your further reply provided much useful
information.

Based on these information, it is likely that "class_err" is executing in
the non-GUI thread. As I stated in the first reply, there is a
multithreading rule in .Net winform that any accessing to the GUI
controls/forms from non-GUI thread code must be marshaled with
Control.Invoke method, or there will be potential race condition and cause
strange behavior.

To check if "class_err" is executed in a non-GUI thread, you may use the
steps below:
1. place a breakpoint in the Form_Load event, while this breakpoint is hit,
open "Debug->Windows->Threads" window to record the current thread(GUI
thread) id.
2. place a breakpoint in "class_err" code, while this breakpoint is hit,
open "Debug->Windows->Threads" window to compare the current thread id with
the previous recorded GUI thread id.

If they differ, it means your code is executing in a worker thread. In this
scenario, you should modify your code in "class_err" to marshal the code
calling to listbox with Control.Invoke. Fixing the winform threading
marshaling issue may resolve your problem.

You may find a lot of information regarding the syntax by searching "VB.net
Control.Invoke" in groups.google.com. If you need help on the details
syntax, please feel free to tell me.

Additionally, how does your timer interact with the threads in your
application? Which type of timer you are using? Normally, there are 3 types
of timers in .Net and they have different threading behavior, please refer
to the article below for details:
"Comparing the Timer Classes in the .NET Framework Class Library"
http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/

Finally, to show a new form in the worker thread, we should use
Application.Run() method to start the message loop instead of just using
the Form.Show, my code snippet below demonstrates a basic logic:

Imports System.Threading
Public Class Form1

Private Shared Sub TimerEventProcessor(ByVal myObject As Object, ByVal
myEventArgs As Timers.ElapsedEventArgs)
myTimer.Stop()
Dim f As New Form
Application.Run(f)
'if you use f.Show, there will be problem
End Sub

Shared myTimer As New System.Timers.Timer
Public Shared Sub ThreadProc()
AddHandler myTimer.Elapsed, AddressOf TimerEventProcessor
myTimer.Interval = 4000
myTimer.Start()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As Thread = New Thread(AddressOf ThreadProc)
t.Start()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Me.NotifyIcon1.Visible = True
Me.Visible = False
End Sub

Private Sub NotifyIcon1_DoubleClick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.NotifyIcon1.Visible = False
Me.Visible = True
End Sub
End Class

This test code works well on my side, both in notifyIcon mode and normal
mode. If you still can not resolve your problem, I recommend you create a
little sample project to demonstrate your problem, this will be more
helpful to the understanding.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.