Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:25:48+00:00 2026-05-28T07:25:48+00:00

I have a code written in VB.Net that will run on multiple systems. One

  • 0

I have a code written in VB.Net that will run on multiple systems. One of the function of that code is to check for files in some folder each minute.If we run code on different system at different times, it is possible that timer will execute the function to check the files at different times on each system. Is there any way ,to make the timer running in each system in sync with each other so that it doent matter when the timer start on each system, they all will check for the file at the same time

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:25:49+00:00Added an answer on May 28, 2026 at 7:25 am

    If I understand your question correctly, you want to call a function every minute but have it synchronized with the system clock. This isn’t entirely straight forward. I’ll tell you my approach and we’ll go from there.

    The Timer class is a good way of executing a given function at an X interval. The problem with this is you want to keep it in sync with when a minute elapses according to the system clock. So we need to make sure we start the timer only when a minute elapses by the clock. Here are a few approaches.

    1. Let the timer fire every second; but before we let it do anything we check to see if a minute has passed according to the clock. If so; then we let it proceed. That would look something like this:

      Module TimerExample
      
          Private _previousTime As DateTime = DateTime.Now
      
          Sub Main()
              Dim timer As New System.Timers.Timer(1000)
              AddHandler timer.Elapsed, AddressOf TimeElapsed
              timer.Start()
              'Run a loop so the console application doesn't quit
              Application.Run()
          End Sub
      
          Sub TimeElapsed(sender As Object, args As ElapsedEventArgs)
              Dim now As DateTime = DateTime.Now
              If now.Minute > _previousTime.Minute Then
                  'A minute elapsed. Do your code here
                  Console.WriteLine("A minute elapsed!")
              End If
              _previousTime = now
          End Sub
      
      End Module
      

      This might be an acceptable solution for you. The only “downside” is that the timer is firing every second; but it doesn’t do anything until a minute has elapsed.

    2. Another alternative might be to use two timers. Use the first timer in a similar fasion to the first example; but use it to start another timer that only elapses every minute. Once you start the second timer, let the first one stop. The only positive to this approach is a timer is only firing every minute. The negatives are the timer will probably start drifting from the system clock over a long period of time. The first example is a better approach; but this is an option if letting a timer fire every second is too expensive (though I really doubt it would be).

    Another thing you may want to handle; maybe not; is when a user changes the system time. You can handle time SystemEvents.TimeChanged to know when that happens.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in my ASP.NET application written in C# that is trying
I have written some code in my VB.NET application to send an HTML e-mail
I've written some tests for .net code that invokes calls to my SQL Server.
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
Most of the code I've written in .NET to make REST calls have been
I have code written in c, which contains some complex algorithms and I want
I'm using some not optimal code written by me... :-| I have following code:
I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have a set of classes that I've written in C++ for a code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.