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 8612189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:33:56+00:00 2026-06-12T04:33:56+00:00

I have created a new Windows Forms Application with C# and .NET 4.0, and

  • 0

I have created a new Windows Forms Application with C# and .NET 4.0, and I have a function that must be called automatically every 60th of a second. My problem, is that I do not know where to call this function. .NET forms don’t appear to have a built-in on-update event.

How would I go about getting this function called every 60th of a second?
Sorry if it is a beginner question.

  • 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-06-12T04:33:57+00:00Added an answer on June 12, 2026 at 4:33 am

    You could set up a Timer to invoke a callback every 16 ms (which is 1/60 sec).

    Important point as mentioned by @spender: If you are requiring very precise timing on this, eg exactly every 1/60 sec precision, you will not be satisfied with this solution. Windows does not natively do high-resolution timing in that vein very well. Props to @spender for the mention.

    Here’s a sample class with a rough outline of how it might look in a plain vanilla class, so you’d need to adapt it to your form:

    You might also want to call this on a background thread, but if you’re new to WinForms, we’ll start in small chunks. Let’s try the timer first, then go from there.

    class Demo{
    
       System.Timers.Timer myTimer;
    
       void InitializeTimer(){
          myTimer = new Timer(16); // elaps every 1/60 sec , appx 16 ms.
          myTimer.ElapsedEventHandler+=new ElapsedEventHandler(myTimerEventHandler); //define a handler
          myTimer.Enabled=true; //enable the timer.
       }
    
       void myTimerEventHandler(object sender, ElapsedEventArgs e){
         // do your thing here
       }
    }
    

    EDIT: Extra demo code for background thread creation and Invoked-based GUI update

    As noted in my comment below, this is not as polished as I would like it, but I think it illustrates the salient points. It defines a BackgroundWorker thread to move the thread invocations to the background; the thread callback checks for the need to call Invoke, and calls right back to itself across a delegate invocation to allow for the custom form update in the “else” block of the “if (InvokeRequired)” statement. In a nutshell, a background thread starts, and starts a timer; when the timer elapses, it calls the updater on the background thread, which checks to see if Invoke must be called, and if it is, performs the thread context switch back to the GUI thread through the recall to the method, which then performs the GUI update. Put your custom update code in that “else” block. I hope this helps!!!

    public partial class Form1 : Form
    {
        delegate void FormUpdateDelegate(object sender, ElapsedEventArgs e);
        public BackgroundWorker backgroundThread; 
        System.Timers.Timer foo;
        Random colorgen = new Random();
        public Form1()
        {
            InitializeComponent();
    
            backgroundThread = new BackgroundWorker();
            backgroundThread.DoWork+=new DoWorkEventHandler(backgroundThread_DoWork);
            backgroundThread.RunWorkerAsync();
        }
    
        public void formUpdater(object sender, ElapsedEventArgs e)
        {
            if (InvokeRequired)
            {
                FormUpdateDelegate d = new FormUpdateDelegate(formUpdater);
                Invoke(d, new object[] { sender, e });
            }
            else
            {
                // Do your form update here
                this.label1.ForeColor = Color.FromArgb(colorgen.Next());
            }
        }
    
        public void backgroundThread_DoWork(object sender, DoWorkEventArgs e)
        {
            foo = new System.Timers.Timer(16);
            foo.Elapsed += new ElapsedEventHandler(formUpdater);
            foo.Start();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
I have a Windows Forms application that was created in Visual Studio 2008 and
I have multiple business entities in VB.NET Windows Forms application. Right now they are
Im using c# .net windows form application. I have created a database which has
I work in C#, .Net 4.0, but I have a Windows Forms application. I
I have created a VB.NET program using windows forms. The program runs on a
Windows Forms, .net 2.0 My main application thread has a form (A). I have
I have created a new method in one of the project's controllers that it
I have created a new silverlight business application in visual studio. It auto generates
I have created a new application using Entity Framework 4.3 database migrations. The migrations

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.