|
-
Aug 21st, 2007, 09:04 AM
#1
Thread Starter
Hyperactive Member
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?
-
Aug 21st, 2007, 09:06 AM
#2
Re: Show Baloon Tip every hour
Hmm, why do you call the GC method on it?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 21st, 2007, 09:25 AM
#3
Thread Starter
Hyperactive Member
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.
-
Aug 21st, 2007, 11:37 AM
#4
Re: Show Baloon Tip every hour
Ah this is why...
' 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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 21st, 2007, 11:49 AM
#5
Thread Starter
Hyperactive Member
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?
-
Aug 21st, 2007, 12:50 PM
#6
Re: Show Baloon Tip every hour
It should keep firing but do you have any other code that may be disabling the timer?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 21st, 2007, 01:08 PM
#7
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
-
Aug 21st, 2007, 03:05 PM
#8
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|