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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:14:06+00:00 2026-05-15T22:14:06+00:00

I have a System.Timers.Timer object that I want to use, but I don’t want

  • 0

I have a System.Timers.Timer object that I want to use, but I don’t want the processing tied to the Timer to interfere with normal to high priority threads. In other words, I’d like to say that I want to process X every 5 seconds as long as nothing else is running.

How could I ensure that my Timer operations are running in a low-priority manner?

  • 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-15T22:14:07+00:00Added an answer on May 15, 2026 at 10:14 pm

    The nice thing about System.Timers.Timer is that you can assign a synchronzing object via the SynchronizingObject property and then exploit it to run the Elapsed event a thread whose priority can be controlled.

    Just assign an instance of the ElapsedEventReceiver to the SynchronizingObject property of your timer.

    Disclaimer: I whipped this up pretty fast so you will need to add your own finishing touches to make it more robust.

    public class ElapsedEventReceiver : ISynchronizeInvoke
    {
        private Thread m_Thread;
        private BlockingCollection<Message> m_Queue = new BlockingCollection<Message>();
    
        public ElapsedEventReceiver()
        {
            m_Thread = new Thread(Run);
            m_Thread.Priority = ThreadPriority.BelowNormal;
            m_Thread.IsBackground = true;
            m_Thread.Start();
        }
    
        private void Run()
        {
            while (true)
            {
                Message message = m_Queue.Take();
                message.Return = message.Method.DynamicInvoke(message.Args);
                message.Finished.Set();
            }
        }
    
        public IAsyncResult BeginInvoke(Delegate method, object[] args)
        {
            Message message = new Message();
            message.Method = method;
            message.Args = args;
            m_Queue.Add(message);
            return message;
        }
    
        public object EndInvoke(IAsyncResult result)
        {
            Message message = result as Message;
            if (message != null)
            {
                message.Finished.WaitOne();
                return message.Return;
            }
            throw new ArgumentException("result");
        }
    
        public object Invoke(Delegate method, object[] args)
        {
            Message message = new Message();
            message.Method = method;
            message.Args = args;
            m_Queue.Add(message);
            message.Finished.WaitOne();
            return message.Return;
        }
    
        public bool InvokeRequired
        {
            get { return Thread.CurrentThread != m_Thread; }
        }
    
        private class Message : IAsyncResult
        {
            public Delegate Method;
            public object[] Args;
            public object Return;
            public object State;
            public ManualResetEvent Finished = new ManualResetEvent(false);
    
            public object AsyncState
            {
                get { return State; }
            }
    
            public WaitHandle AsyncWaitHandle
            {
                get { return Finished; }
            }
    
            public bool CompletedSynchronously
            {
                get { return false; }
            }
    
            public bool IsCompleted
            {
                get { return Finished.WaitOne(0); }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that uses a System.Timers.Timer to update the position of motors.
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
Ok so I am using System.Timers.Timer in .Net 4 with C#. I have my
I have a .NET Windows Service (.NET 3.5) with a timer ( System.Timers.Timer ).
I have the following struct private struct sData{ public int volume; public System.Timers.Timer aliveTimer;
I have been checking out some of the possible timers lately, and System.Threading.Timer and
I created a class that implements a System.Timers.Timer with an elapse event. private void
In system we have methods that lock an object by specific params. As implementation,
I have a class that created a threading .timer . System.Threading.Timer timer; TimerCallback cb
I have an issue with System.Threading.Timer. I am scheduling some actions using a time

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.