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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:48:31+00:00 2026-06-05T05:48:31+00:00

I am making a program which has to check a data base once on

  • 0

I am making a program which has to check a data base once on every 30 or 60 minutes and display the results, if there are any, in the windows form interface. Of course, the other functions which the from provides access to, should still be usable while the data base check is being executed. To this end, I am using System.Timers.Timer which executes a method on a different thread from the UI one (If there is something wrong with using this approach, please feel free to comment on it). I wrote a small and simple program in order to test hot things work, only to notice that I cant really set the Interval to over ~ 1 minute ( I need 30 minutes to an hour). I came up with this solution:

public partial class Form1 : Form
{

    int s = 2;

    int counter = 1; //minutes counter

    System.Timers.Timer t;

    public Form1()
    {
        InitializeComponent();

        t = new System.Timers.Timer();
        t.Elapsed += timerElapsed;
        t.Interval = 60000;
        t.Start();
        listBox1.Items.Add(DateTime.Now.ToString());
    }


    //doing stuff on a worker thread
    public void timerElapsed(object sender, EventArgs e)
    {
        //check of 30 minutes have passed
        if (counter < 30)
        {
            //increment counter and leave method
            counter++;
            return;
        }
        else
        {
            //do the stuff
            s++;
            string result = s + "   " + DateTime.Now.ToString() + Thread.CurrentThread.ManagedThreadId.ToString();
            //pass the result to the form`s listbox
            Action action = () => listBox2.Items.Add(result);
            this.Invoke(action);
            //reset minutes counter
            counter = 0;
        }


    }

    //do other stuff to check if threadid`s are different
    //and if the threads work simultaneously
    private void button1_Click(object sender, EventArgs e)
    {
        for (int v = 0; v <= 100; v++)
        {

            string name = v + " " + Thread.CurrentThread.ManagedThreadId.ToString() +
                " " + DateTime.Now.ToString(); ;
            listBox1.Items.Add(name);
            Thread.Sleep(1000); //so the whole operation should take around 100 seconds
        }

    }
}

But this way, the Elapsed event is being raised and the timerElapsed method called once every minute, it seems kinda useless. Is there a way to actually set longer timer interval ?

  • 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-05T05:48:34+00:00Added an answer on June 5, 2026 at 5:48 am

    Interval is in miliseconds,so it seems that you’ve set your interval for 60 seconds:

    t.Interval = 60000; // 60 * 1000 (1 minute)
    

    If you want to have 1 hour interval then you need to change your interval to:

    t.Interval = 3600000; // 60 * 60 * 1000 (1 hour)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a C Assessment Program through Java, which has a bunch of programming
I have a python program which opens a new windows to display some 'about'
Making a small WCF test program which is based on a Store that has
I am currently making an objective c program in which there are 4 shapes
I am coding a program which needs making sure if the kernel has loaded
So I'm making a program which is supposed to print a horizontal histogram of
I'm making a program which create a RAW socket in order to read all
I am making a timetabling program which does one to one matches from SubjectTeacherPeriod
I am making a program with native C++ and the WinAPI. This program has
I am currently making a program in which one of its functions is to

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.