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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:54:58+00:00 2026-05-25T00:54:58+00:00

Is there any good example of poller class? Thread safe with wait handles, with

  • 0

Is there any good example of poller class? Thread safe with wait handles, with background/foreground options and common start, stop, pause, resume calls?

I found examples like CruiseControl poller but ideally I would like to avoiding implementing IPollable every time I want to poll for something.

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-05-25T00:54:59+00:00Added an answer on May 25, 2026 at 12:54 am

    I don’t know of a standard one other than the basic .NET timer class, but here’s a wrapper class for the .NET timer that uses a delegate rather than the IPollable interface of the wrapper you found. it also features a bit of locking and some methods that come in handy. you may want to extend and improve it yourself for pause/resume and logging, for example. good luck.

    public class TimerWrapper
    {
        private object defaultLock = new object();
        private object functionLock = null;
        private object classLock = new object();
        protected bool isRunning = false;
        protected bool isRepeating = false;
        protected Timer timer = null;
        protected Action timerFn = null;
    
        public TimerWrapper(Action timerFn)
        {
            if (timerFn == null)
            {
                throw new ArgumentNullException("timerFn", "Invalid timer delegate supplied at construction");
            }
            // Execute this function upon expiration of the timer
            this.timerFn = timerFn;
        }
    
        public TimerWrapper(Action timerFn, ref object timerLock) : this(timerFn)
        {
            // Use the locking object passed at construction
            this.functionLock = timerLock;
        }
    
        protected void TimerFunction(object state)
        {
            if (timerFn != null)
            {
                lock (classLock)
                {
                    // Lock on function lock if available or default lock otherwise
                    lock (functionLock ?? defaultLock)
                    {
                        // If timer isn't repeating it's now no longer running
                        if (!IsRepeating)
                        {
                            IsRunning = false;
                        }
    
                        // Execute this function because timer has expired
                        timerFn();
                    }
                }
            }
        }
    
        public void Stop()
        {
            lock (classLock)
            {
                if (timer != null)
                {
                    timer.Dispose();
                    timer = null;
                }
    
                IsRunning = false;
            }
        }
    
        public void Start(int duetime)
        {
            // Start the timer for a single run
            Start(duetime, Timeout.Infinite);
        }
    
        public void Start(int duetime, int period)
        {
            if (duetime > 0)
            {
                lock (classLock)
                {
                    // Stop the timer
                    Stop();
    
                    // Start the timer for either a single run or repeated runs
                    timer = new Timer(TimerFunction, null, duetime, period);
    
                    IsRunning = true;
                    IsRepeating = (period != Timeout.Infinite);
                }
            }
        }
    
        public bool IsRepeating
        {
            get
            {
                return isRepeating;
            }
            protected set
            {
                if (isRepeating != value)
                {
                    isRepeating = value;
                }
            }
        }
    
        public bool IsRunning
        {
            get
            {
                return isRunning;
            }
            protected set
            {
                if (isRunning != value)
                {
                    isRunning = value;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any good example to give the difference between a struct and a
Is there any good way to deal with the class renaming refactor from Resharper
Is there any good practice to avoid your jQuery code silently fail? For example:
Is there any good tutorial and example for restful web services using jquery &
Is there any good example/tutorial sites where I can refer to regarding building website/web
Are there any good example of a UITabBarController inside of a UINavigationController? I have
Is there any good way to resize, for example the form height when a
Is there any good example of how to encrypt and decrypt image and other
Are there any good guides on making WPF applications 508 compliant? For example, does
Are there any good examples (websites or books) around of how to build a

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.