Class timer2
Timer that calls callback function in other thread (thread pool) and can be used in any thread.
public class timer2
Remarks
Uses System.Threading.Timer. Unlike timer, the thread that sets the timer does not have to retrieve/dispatch messages. The callback function is called in a random thread of the thread pool, therefore its code is not thread-safe (may need to lock etc). The actual minimal time interval/period is 10-20 ms, because the system timer period usually is 15.25 ms. Timer action delegates are protected from GC.
Examples
This example sets 3 timers.
timer2.after(500, _ => print.it("after 500 ms"));
timer2.every(1000, _ => print.it("every 1000 ms"));
var t3 = new timer2(_ => print.it("after 3000 ms")); t3.After(3000); //the same as timer2.after
5.s();
Namespace: Au
Assembly: Au.dll
Constructors
Name | Description |
---|---|
timer2(Action<timer2>) | Sets callback function. |
Properties
Name | Description |
---|---|
Tag | Something to attach to this variable. |
Methods
Name | Description |
---|---|
After(long) | Starts one-time timer or changes timeout/period. |
Every(long, long?) | Starts periodic timer or changes timeout/period. |
Stop(bool) | Stops the timer, and by default disposes. |
after(long, Action<timer2>, object) | Creates and starts new one-time timer. |
every(long, Action<timer2>, object, long?) | Creates and starts new periodic timer. |