Is there a timer class in C# that isn't in the Windows.Forms namespace?

后端 未结 6 1268

I want to use a timer in my simple .NET application written in C#. The only one I can find is the Windows.Forms.Timer class. I don\'t want to reference this namespace just f

6条回答
  •  一整个雨季
    2020-12-30 03:53

    There are at least the System.Timers.Timer and System.Threading.Timer classes that I'm aware of.

    One thing to watch out though (if you haven't done this before already), say if you already have the System.Threading namespace in your using clause already but you actually want to use the timer in System.Timers you need to do this:

    using System.Threading;
    using Timer = System.Timers.Timer;
    

    Jon Skeet has an article just on Timers in his multithreading guide, it's well worth a read: http://www.yoda.arachsys.com/csharp/threads/timers.shtml

提交回复
热议问题