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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:18:59+00:00 2026-05-16T16:18:59+00:00

There are times in my application, when I need to invoke my timer manually.

  • 0

There are times in my application, when I need to invoke my timer manually.

I’ve tried the following:

int originalInterval = t.Interval;
t.Interval = 0;
t.Interval = originalInterval;

but it wasn’t consistent.

I’ve created a new timer, inheriting from System.Timers.Timer, and exposed a “Tick” method – but the problem was that the “Elapsed” event then fired synchronously.

When I implemented the “Tick” with a new Thread – the results were, again, not consistent.

Is there a better way to implement it?

  • 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-16T16:18:59+00:00Added an answer on May 16, 2026 at 4:18 pm

    I once had the same problem, so I used the AutoResetEvent to know if the Elapsed was invoked successfully:

    /// <summary>
    /// Tickable timer, allows you to manually raise a 'Tick' (asynchronously, of course)
    /// </summary>
    public class TickableTimer : System.Timers.Timer
    {
        public new event ElapsedEventHandler Elapsed;
    
        private System.Threading.AutoResetEvent m_autoResetEvent = new System.Threading.AutoResetEvent(true);
    
        public TickableTimer()
            : this(100)
        {
        }
    
        public TickableTimer(double interval)
            : base(interval)
        {
            base.Elapsed += new ElapsedEventHandler(TickableTimer_Elapsed);
        }
    
        public void Tick()
        {
            new System.Threading.Thread(delegate(object sender)
            {
                Dictionary<string, object> args = new Dictionary<string, object>
                {
                    {"signalTime", DateTime.Now},
                };
                TickableTimer_Elapsed(this, Mock.Create<ElapsedEventArgs>(args));
            }).Start();
            this.m_autoResetEvent.WaitOne();
        }
    
        void TickableTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            m_autoResetEvent.Set();
            if (this.Elapsed != null)
                this.Elapsed(sender, e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any good ways to limit the number of times an application can
I'm writing a Java Swing application using the Metal look-and-feel. Every time there is
What are the differences between #import and #include in Objective-C and are there times
There are times when I want to use mootools for certain things and Prototype
There are times when I want to test new code from the forums or
There are numerous times you have an interface that accepts similar type arguments that
I was wondering if there are any times where it's advantageous to use an
Are there any products that will decrease c++ build times? that can be used
How do I get a method's execution time? Is there a Timer utility class
So the official XML-RPC standard doesn't support 64-bit values. But in these modern times,

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.