SoFunction
Updated on 2025-03-01

Add SetTimeout and SetInterval functions to c#


/// <summary>
2         /// Execute the specified expression after the specified time
 3         /// </summary>
4         // <param name="interval">Time elapsed between events (in milliseconds)</param>
5         // <param name="action">Expression to be executed</param>
 6         public static void SetTimeout(double interval, Action action)
 7         {
 8              timer = new (interval);
 9              += delegate(object sender,  e)
10             {
11                  = false;
12                 action();
13             };
14              = true;
15         }
16         /// <summary>
17           // Repeat the specified expression in the specified time period
18         /// </summary>
19         // <param name="interval">Time elapsed between events (in milliseconds)</param>
20        // <param name="action">Expression to be executed</param>
21         public static void SetInterval(double interval, Action<ElapsedEventArgs> action)
22         {
23              timer = new (interval);
24              += delegate(object sender,  e)
25             {
26                 action(e);
27             };
28              = true;
29         }