Results 1 to 7 of 7

Thread: No time for timers

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271

    No time for timers

    Hi,

    I'm writing a program that needs to run a sub once on the hour every hour.

    is there w way to do this without using a timer control?

    as this takes up too much reasources when running 24/7

    Thanks
    §tudz

    Studzworld.com - Portfolio

  2. #2
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    You have to use some sort of timing object. Here is the way I would do it if I didnt' want to use a "visual control"




    Code:
        Private MyTimer As System.Timers.Timer
    
        Private Sub MyTimerSub(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
    
            'Code every hour goes here
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            MyTimer = New System.Timers.Timer(3600000)
            AddHandler MyTimer.Elapsed, AddressOf Me.MyTimerSub
            MyTimer.Start()
    
        End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    that is exactly what I >>am<< using.

    The problem is that the timer is going tick tick tick tick.... tick tick tick... and every time that timer ticks it uses a percentage of memory after a few days of running the computers it is running on has slowed down, due to the timer using all the resources.

    I wanted to know if there was a way to run the sub using the system clock? so when it was exactly an hour from last run it will run again.
    §tudz

    Studzworld.com - Portfolio

  4. #4
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    I think that no matter what you do, you'll have some process running at all times checking on the time to see what time it is.

    Your best bet would be to setup the scheduler that comes with WinXP to schedule the app to run every hour. They windows is doing all the processing and your app will only run every hour.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    No matter where it is done, a timer has to be involved.

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    You say that after a few days of running the timer has consumed too much of your resources. In the beginning of the sub you wish to run, set Timer.Enabled to false and then set it to true just before the sub is vacated when you will obviously have to synchronise the timer with the actual time.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    right ok thanks,

    well never mind

    I have just added a log to the program, and I have just realised that the program runs every 10mins lol, in stead of every hour... oops... maybe changing that will help to.

    Thanks again,
    §tudz

    Studzworld.com - Portfolio

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