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

  • Home
  • SEARCH
  • 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 7802669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:19:38+00:00 2026-06-02T01:19:38+00:00

I am using a DispatchTimer to do something every second, how can I make

  • 0

I am using a DispatchTimer to do something every second, how can I make it do Something for a set amount of time say 1 minute or 2 minutes? Do I need anther nested DispatcherTimer?

My code is below

System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();

    private void StartButton_Click(object sender, RoutedEventArgs e)
    {
        TimeSpan interval;
        interval = (TimeSpan)intervalPicker.Value;
        dt.Interval = interval;
        dt.Tick += new EventHandler(dt_Tick);
        dt.Start();
    }

    void dt_Tick(object sender, EventArgs e)
    {
       //Do Something
    }

I would appreciate if you could help me thanks.

  • 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-02T01:19:39+00:00Added an answer on June 2, 2026 at 1:19 am

    Use the Stopwatch class:

    Stopwatch sw = new Stopwatch();
    
    private void StartButton_Click(object sender, RoutedEventArgs e)
    {
        sw.Start();
        ...
    }
    
    void dt_Tick(object sender, EventArgs e)
    {
       // stops the timer after 66 seconds
       if(sw.ElapsedMilliseconds/1000 > 66)
       {
           dt.Stop();
           sw.Reset();
       }          
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a Dispatch timer set to fire every 20 seconds in which
Using PHP, I can convert MySQL data or static table data to csv, Excel,
When the user does something (touch on a StackPanel, in this case), I need
I'm using a Threading.DispatcherTimer and every tick of the timer runs a subroutine. Is
I'm trying to measure the elapsed time in milliseconds between keypress events using a
Using Django, how do I generate the value of a field the first time
Using Android 2.1+. I have a service that gets killed from time to time
Using boost python I need create nested namespace. Assume I have following cpp class
Using Windows, Mercurial, and the extdiff extension (for Mercurial). I was trying to set
Using the opencart image manager how would I set the upload to automatically remove:

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.