Raihan Iqbal

Hi

How can I monitor the system clock and have some events fire when the hour or minute changes Or should I just run a thread that keeps checking the time in an infinite loop I think the latter would consume lot of resources.



Re: Visual C# General Monitor System clock and fire events accordingly

micvos

The system timer idoesn't fir events. The best way to go is indeed to create a thread and check for it every now and then. lets say every second. If you use the Thread.Sleep(1000) function it doesn't really consume a lot of resources.




Re: Visual C# General Monitor System clock and fire events accordingly

Figo Fei - MSFT

Hi,

Otherwise, you can choose timer to do this.

Set a fair interval, and to check the DateTime.Now value in tick event.

That's the idea.

Thanks.






Re: Visual C# General Monitor System clock and fire events accordingly

Sean Hederman

Or, calculate the number of millseconds to the time you want and sleep the thread until then...






Re: Visual C# General Monitor System clock and fire events accordingly

RizwanSharp

Yes you can use a Thread and make it sleep for 2-5 seconds and check the time in each iteration using DateTime.Now. It'll not consume much CPU if you give it delay using Thread.Sleep().... But you have to bear that tolerance which is a little delay when thread is slept.

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp