NotifyIcon Click events not firing

J

Jason

I have an application where I use the NotifyIcon and it's Baloon tip to
notify users when a new version of the application is available.

In the NotifyIcon.Click and NotifyIcon.BalloonTipClicked events, I have code
that closes the NotifyIcon and opens a URL using the users default browser.

This code consistently works just fine when the application runs under
Visual Studio and the VSHost but the events fail to fire when the application
is deployed to client machines (confirmed on both XP and Vista.)

I've added a test message box that gives me positive notification when the
click event is processed in my code so I know that the code works fine under
VS2008, but not from a standalone copy of the application.

In addition, as part of my troubleshooting, I have added <STAThread()> _
Sub main() to my main entry point in order to force Single Threaded
Apartment on my application, but this hasn't helped.

The pertinent code elements are shown below:

Private Sub tmrUpdateCheckTimer_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles tmrUpdateCheckTimer.Elapsed
'When this timer event is triggered, check for updates and notify
the user.
'Disable the timer for the rest of the session.
Me.tmrUpdateCheckTimer.Enabled = False
If My.Computer.Network.IsAvailable Then Check_For_Version_Update()
End Sub

Public Sub Notification(ByVal Title As String, ByVal Body As String,
Optional ByVal ActionURL As String = "")
Me.NotifyIcon.BalloonTipTitle = Title
Me.NotifyIcon.BalloonTipText = Body
If Len(ActionURL) > 0 Then NotifyIcon.Tag = ActionURL Else
NotifyIcon.Tag = ""
Me.NotifyIcon.Visible = True
Me.NotifyIcon.ShowBalloonTip(9)
End Sub

Private Sub NotifyIcon_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NotifyIcon.Click
MsgBox("Clicked 2", MsgBoxStyle.OkOnly, "Test: Click Detection")
Call NotifyIcon_BalloonTipClicked(sender, e)
End Sub

Private Sub NotifyIcon_BalloonTipClicked(ByVal sender As Object, ByVal e
As System.EventArgs) Handles NotifyIcon.BalloonTipClicked
MsgBox("Clicked", MsgBoxStyle.OkOnly, "Test: Click Detection")
If Len(NotifyIcon.Tag.ToString) > 0 Then
Dim myTargetURL As String = NotifyIcon.Tag.ToString
System.Diagnostics.Process.Start(myTargetURL)
Application.DoEvents()
End If
Me.NotifyIcon.Visible = False
End Sub

Thanks,

Jason

This message was cross posted in Visual Basic Language Forum also.
 
M

Mark S. Milley

Hi Jason -

Are you sure that their firewalls are allowing your application to reach the
internet?

I'm not sure of the exact mechanics of Windows Firewall, but my suspicion is
that simply calling the My.Computer.Network.IsAvailable may not be enough to
determine whether it is actually available; the OS could be misreporting the
network availability to your app. You may have to go ahead and attempt to
access your remote procedure (trapping the resultant exception) in order to
get Windows Firewall to throw up the "This Application is Trying to Access
the Internet (Deny/Allow)" dialog.

Give that a shot, and let me know how it works for you.

Regards,

-Mark
 
J

Jason

Thanks Mark, but that's not the issue at all. That bit of code was just for
background on what I was trying to do and actually works just fine for my
purposes.

The actual issue is that the Click events aren't firing. You'll notice that
I even added some temporary message boxes to very clearly indicate whether
each bit of code ran.

When I run the app from VS2008, those bits of code execute every time. When
I install the app on a seperate machine OR run it on the dev machine as a
normal app (not under VSHost) they fail to execute at all.

Jason
 
J

\Ji Zhou [MSFT]\

Hello Jason,

Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
[MSFT] and I will be working on this issue with you.

I have tried to but cannot reproduce your issue on my side. From your
codes, I think the logical is, every time the Timer's elapsed event fires,
we call the Check_For_Version_Update() function. From the
Check_For_Version_Update() function, we judge a condition statement, and
determine whether to call Notification() function. In the Notification()
function, we show our balloon tip, right?

For I do not see your codes in the Check_For_Version_Update() function. I
write my simulated version to test on my side. The whole codes are as
follows,

Public Class Form1
Dim WithEvents tmrUpdateCheckTimer As System.Timers.Timer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
tmrUpdateCheckTimer = New System.Timers.Timer()
tmrUpdateCheckTimer.Interval = 3000
tmrUpdateCheckTimer.Enabled = True
End Sub


Private Sub tmrUpdateCheckTimer_Elapsed(ByVal sender As Object, ByVal e
As System.Timers.ElapsedEventArgs) Handles tmrUpdateCheckTimer.Elapsed
'When this timer event is triggered, check for updates and notify
the user.
'Disable the timer for the rest of the session.
Me.tmrUpdateCheckTimer.Enabled = False
If My.Computer.Network.IsAvailable Then Check_For_Version_Update()
End Sub

Private Sub Check_For_Version_Update()
Dim findUpdateVersion = True
If (findUpdateVersion) Then
Notification("Test Title", "Test Body", "http://localhost")
End If
End Sub

Public Sub Notification(ByVal Title As String, ByVal Body As String,
Optional ByVal ActionURL As String = "")
Me.NotifyIcon.BalloonTipTitle = Title
Me.NotifyIcon.BalloonTipText = Body
If Len(ActionURL) > 0 Then
NotifyIcon.Tag = ActionURL
Else
NotifyIcon.Tag = ""
End If
Me.NotifyIcon.Visible = True
Me.NotifyIcon.ShowBalloonTip(9)
End Sub

Private Sub NotifyIcon_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NotifyIcon.Click
MsgBox("Clicked 2", MsgBoxStyle.OkOnly, "Test: Click Detection")
Call NotifyIcon_BalloonTipClicked(sender, e)
End Sub

Private Sub NotifyIcon_BalloonTipClicked(ByVal sender As Object, ByVal
e As System.EventArgs) Handles NotifyIcon.BalloonTipClicked
MsgBox("Clicked", MsgBoxStyle.OkOnly, "Test: Click Detection")
If Len(NotifyIcon.Tag.ToString) > 0 Then
Dim myTargetURL As String = NotifyIcon.Tag.ToString
System.Diagnostics.Process.Start(myTargetURL)
Application.DoEvents()
End If
Me.NotifyIcon.Visible = False
End Sub
End Class

No matter I run the application within Visual Studio or deploy it and run
it at client machines. It always works as expected. The click event of
NotifyIcon and BallonTip fires OK. I can see the message box to pop up, as
well as the target site's launching. One important thing to be mentioned is
that, in the Notification() function, I have changed the codes

If Len(ActionURL) > 0 Then NotifyIcon.Tag = ActionURL Else
NotifyIcon.Tag = ""

to

If Len(ActionURL) > 0 Then
NotifyIcon.Tag = ActionURL
Else
NotifyIcon.Tag = ""
End If

Actually, without the End If statement, the NotifyIcon.Tag="" will always
be executed. So, at the later time, the target site will never be launched.
This may be problematical in the design logical, but I do not think it will
result into the message box's not poping up.

To do a future investigation on this issue and narrow down the problem,
would you mind to send me an setup msi file of your test project? So, I can
try to setup the application on my side, and run it to see what the problem
is there. You can access me by this email address, (e-mail address removed)

Have a nice day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

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://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jason

reply.

The IF-Then-Else statement that you noticed on two lines is actually on a
single line in my code and works just fine. But, I re-formatted it and added
the End If anyways.

I created a temporary application and pasted your code into it, added a
NotifyIcon to the form and assigned an icon to it for testing purposes. Both
the NotifyIcon Click event and the NotifyIcon.BaloonClick events worked
correctly under VS2008 and as a standalone application. So, what's the
difference between my original code and this test application? I started
experimenting a bit.

I dug into the form designer code and found the following:

My original code was:
'
'NotifyIcon
'
Me.NotifyIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info
Me.NotifyIcon.BalloonTipText = "Click to visit the website for more
information."
Me.NotifyIcon.BalloonTipTitle = "An Update is available for IAS"
Me.NotifyIcon.Icon = CType(resources.GetObject("NotifyIcon.Icon"),
System.Drawing.Icon)
Me.NotifyIcon.Text = "IAS Notifications"

The test app was:
'
'NotifyIcon
'
Me.NotifyIcon.Icon = CType(resources.GetObject("NotifyIcon.Icon"),
System.Drawing.Icon)
Me.NotifyIcon.Text = "NotifyIcon"
Me.NotifyIcon.Visible = True


I pasted the test app code over the original app code as an experiment.
Then I set the initial visibility to false. Now, when I run the app, the
events appear to fire correctly under VS2008 and on two other machines.

So, I assume that one of the differences above had an un-intended side
effect that was causing the failure.

Thanks for your help.

Jason


""Ji Zhou [MSFT]"" said:
Hello Jason,

Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
[MSFT] and I will be working on this issue with you.

I have tried to but cannot reproduce your issue on my side. From your
codes, I think the logical is, every time the Timer's elapsed event fires,
we call the Check_For_Version_Update() function. From the
Check_For_Version_Update() function, we judge a condition statement, and
determine whether to call Notification() function. In the Notification()
function, we show our balloon tip, right?

For I do not see your codes in the Check_For_Version_Update() function. I
write my simulated version to test on my side. The whole codes are as
follows,

Public Class Form1
Dim WithEvents tmrUpdateCheckTimer As System.Timers.Timer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
tmrUpdateCheckTimer = New System.Timers.Timer()
tmrUpdateCheckTimer.Interval = 3000
tmrUpdateCheckTimer.Enabled = True
End Sub


Private Sub tmrUpdateCheckTimer_Elapsed(ByVal sender As Object, ByVal e
As System.Timers.ElapsedEventArgs) Handles tmrUpdateCheckTimer.Elapsed
'When this timer event is triggered, check for updates and notify
the user.
'Disable the timer for the rest of the session.
Me.tmrUpdateCheckTimer.Enabled = False
If My.Computer.Network.IsAvailable Then Check_For_Version_Update()
End Sub

Private Sub Check_For_Version_Update()
Dim findUpdateVersion = True
If (findUpdateVersion) Then
Notification("Test Title", "Test Body", "http://localhost")
End If
End Sub

Public Sub Notification(ByVal Title As String, ByVal Body As String,
Optional ByVal ActionURL As String = "")
Me.NotifyIcon.BalloonTipTitle = Title
Me.NotifyIcon.BalloonTipText = Body
If Len(ActionURL) > 0 Then
NotifyIcon.Tag = ActionURL
Else
NotifyIcon.Tag = ""
End If
Me.NotifyIcon.Visible = True
Me.NotifyIcon.ShowBalloonTip(9)
End Sub

Private Sub NotifyIcon_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NotifyIcon.Click
MsgBox("Clicked 2", MsgBoxStyle.OkOnly, "Test: Click Detection")
Call NotifyIcon_BalloonTipClicked(sender, e)
End Sub

Private Sub NotifyIcon_BalloonTipClicked(ByVal sender As Object, ByVal
e As System.EventArgs) Handles NotifyIcon.BalloonTipClicked
MsgBox("Clicked", MsgBoxStyle.OkOnly, "Test: Click Detection")
If Len(NotifyIcon.Tag.ToString) > 0 Then
Dim myTargetURL As String = NotifyIcon.Tag.ToString
System.Diagnostics.Process.Start(myTargetURL)
Application.DoEvents()
End If
Me.NotifyIcon.Visible = False
End Sub
End Class

No matter I run the application within Visual Studio or deploy it and run
it at client machines. It always works as expected. The click event of
NotifyIcon and BallonTip fires OK. I can see the message box to pop up, as
well as the target site's launching. One important thing to be mentioned is
that, in the Notification() function, I have changed the codes

If Len(ActionURL) > 0 Then NotifyIcon.Tag = ActionURL Else
NotifyIcon.Tag = ""

to

If Len(ActionURL) > 0 Then
NotifyIcon.Tag = ActionURL
Else
NotifyIcon.Tag = ""
End If

Actually, without the End If statement, the NotifyIcon.Tag="" will always
be executed. So, at the later time, the target site will never be launched.
This may be problematical in the design logical, but I do not think it will
result into the message box's not poping up.

To do a future investigation on this issue and narrow down the problem,
would you mind to send me an setup msi file of your test project? So, I can
try to setup the application on my side, and run it to see what the problem
is there. You can access me by this email address, (e-mail address removed)

Have a nice day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

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://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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