Show Baloon Tip every hour
I am trying to show a balloon tip every hour that my form is minimized to the tray. I allready have the minimize part done but how do I set the timer once it is down and then show the message every hour. I have some code I pulled from MSDN but I am not sure how to apply it to my situation. Also I have the timer set to 10 seconds here so that I can see the balloon tip for testing.
vb Code:
Private Sub SetTimer()
Dim aTimer As New System.Timers.Timer()
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.Interval = 10000
aTimer.Enabled = True
GC.KeepAlive(aTimer)
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
ShowCSABaloon()
End Sub
Also will this timer have a noticable effect on performance?
Re: Show Baloon Tip every hour
Hmm, why do you call the GC method on it?
Re: Show Baloon Tip every hour
This is mostly a copy and paste from the MSDN article and I don't really understand it all yet.
' Keep the timer alive until the end of Main. - However, KeepAlive must be used at the end of Main, to prevent the JIT compiler from allowing aggressive garbage collection to occur before Main ends.
Re: Show Baloon Tip every hour
Ah this is why...
Quote:
' Normally, the timer is declared at the class level, so
' that it doesn't go out of scope when the method ends.
' In this example, the timer is needed only while Main
' is executing. However, KeepAlive must be used at the
' end of Main, to prevent the JIT compiler from allowing
' aggressive garbage collection to occur before Main
' ends.
So their example is based in a Modules sub Main and the keepalive is for maintianing the object existance so it doesnt get disposed. Since you are using a form based timer you wont have that problem.
Re: Show Baloon Tip every hour
Ok that makes sence and I kind of suspected that may be the case but I wasn't sure enough to remove it. So now I have this...
vb Code:
'
Private Sub SetTimer(ByVal intTimeSpan As Integer)
Dim aTimer As New System.Timers.Timer()
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.Interval = intTimeSpan
aTimer.Enabled = True
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
ShowCSABaloon()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SetTimer(3600000)
End Sub
My code, as is, will pop up the balloon after the first hour but how do I keep it poping up every hour the applications is open?
Re: Show Baloon Tip every hour
It should keep firing but do you have any other code that may be disabling the timer?
Re: Show Baloon Tip every hour
As long as the timer is enabled, it should keep firing off.
Try a smaller interval, like a minute for testing.
-tg
Re: Show Baloon Tip every hour
I didn't realize it would keep running in an automatic "loop" like that. I thought I would have to set it to do so. Anyway I have to do a little more testing but it appears that I can set it to start when the form is minimized and it will keep running in the back ground as needed.