Results 1 to 8 of 8

Thread: Show Baloon Tip every hour

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    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:
    1. Private Sub SetTimer()
    2.         Dim aTimer As New System.Timers.Timer()
    3.         AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
    4.         aTimer.Interval = 10000
    5.         aTimer.Enabled = True
    6.         GC.KeepAlive(aTimer)
    7.     End Sub
    8.     Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
    9.         ShowCSABaloon()
    10.     End Sub
    Also will this timer have a noticable effect on performance?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    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:
    1. '
    2.     Private Sub SetTimer(ByVal intTimeSpan As Integer)
    3.         Dim aTimer As New System.Timers.Timer()
    4.         AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
    5.         aTimer.Interval = intTimeSpan
    6.         aTimer.Enabled = True
    7.     End Sub
    8.     Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
    9.         ShowCSABaloon()
    10.     End Sub
    11.  
    12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    13.         SetTimer(3600000)
    14.     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?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    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
  •  



Click Here to Expand Forum to Full Width