c# timer without timer

public void OnStart()
    _registeredWait = ThreadPool.RegisterWaitForSingleObject(_stop, 
        new WaitOrTimerCallback(PeriodicProcess), null, 5000, false);

public void OnStop()

private void PeriodicProcess(object state, bool timeout)
    if (timeout)
        // Periodic processing here
        // Stop any more events coming along

private ManualResetEvent _stop = new ManualResetEvent(false);
private RegisteredWaitHandle _registeredWait;

//It's the method for periodically calling some methothds without using Timers. I think it is more elegant solution for this.

//Waiting process works in separate thread pool. Calling method works in main thread. Be carefull with that.

No comments:

Post a Comment