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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:58:44+00:00 2026-05-16T07:58:44+00:00

I am writing an app which uses a timer to display a countdown on

  • 0

I am writing an app which uses a timer to display a countdown on screen to when some event happens. I want to reuse the timer, as it would be handy for a few things in the app, so I specify the words I want to wrap round the timer. For example, the following function call:

CountdownTimer(90, "You have ", " until the computer reboots");

would show:

You have 1 minute 30 seconds until the computer reboots

and then count down.

I am using the following code:

    private void CountdownTimer(int Duration, string Prefix, string Suffix)
    {
        Countdown = new DispatcherTimer();
        Countdown.Tick += new EventHandler(Countdown_Tick);
        Countdown.Interval = new TimeSpan(0, 0, 1);

        CountdownTime = Duration;
        CountdownPrefix = Prefix;
        CountdownSuffix = Suffix;
        Countdown.Start();
    }

    private void Countdown_Tick(object sender, EventArgs e)
    {
        CountdownTime--;
        if (CountdownTime > 0)
        {
            int seconds = CountdownTime % 60;
            int minutes = CountdownTime / 60;

            Timer.Content = CountdownPrefix;

            if (minutes != 0)
            {
                Timer.Content = Timer.Content + minutes.ToString() + @" minute";
                if (minutes != 1) { Timer.Content = Timer.Content + @"s"; }
                Timer.Content = Timer.Content + " ";
            }

            if (seconds != 0)
            {
                Timer.Content = Timer.Content + seconds.ToString() + @" second";
                if (seconds != 1) { Timer.Content = Timer.Content + @"s"; }
            }

            Timer.Content = Timer.Content + CountdownSuffix;

        }
        else
        {
            Countdown.Stop();
        }

    }

How do I make this run synchronously? For example I would want the following to wait 90 seconds and then reboot:

CountdownTimer(90, "You have ", " until the computer reboots");
ExitWindowsEx(2,0)

Whereas it calls the reboot immediately at present.

Any pointers would be most welcome!

Thanks,

Ben

  • 1 1 Answer
  • 1 View
  • 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-16T07:58:45+00:00Added an answer on May 16, 2026 at 7:58 am

    Personally, I’d recommend having a callback happen at the end of your CountdownTimer – perhaps taking an Action as an argument, such that when it completed it’d be called.

    private Action onCompleted;
    private void CountdownTimer(int Duration, string Prefix, string Suffix, Action callback)
    {
        Countdown = new DispatcherTimer();
        Countdown.Tick += new EventHandler(Countdown_Tick);
        Countdown.Interval = new TimeSpan(0, 0, 1);
    
        CountdownTime = Duration;
        CountdownPrefix = Prefix;
        CountdownSuffix = Suffix;
        Countdown.Start();
    
        this.onCompleted = callback;
    }
    ...
        else
        {
            Countdown.Stop();
            Action temp = this.onCompleted; // thread-safe test for null delegates
            if (temp != null)
            {
                temp();
            }
        }
    

    Then you could just change your usage to:

    CountdownTimer(90, "You have ", " until the computer reboots", 
        () => ExitWindowsEx(2,0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a timer web app,which records start time and stop time.It uses
I am writing small app, using Play Framework 2.0 which uses Ebean as ORM.
I'm writing an app which will be used mainly on phones, but which some
I am writing a web app which works on subdomains. I would also like
I'm writing an iPhone app which uses GLSL shaders to perform transformations on textures,
I am writing an iPhone app which uses core data for storage. All of
I've been writing a small Facebook app which uses the unified_thread table using FQL.
I am writing an app which uses GnuPlot for ploting data. Instead of using
I am writing an app which uses core-data to store my data. Included in
I'm writing an iPhone app which uses a keypad that includes a decimal point.

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.