Call Example:
Execution effect:
2.
Implementation code:
Copy Code code as follows:
<summary>
2///executes the specified expression after the specified time
3///</summary>
4///<param name= The time elapsed between "interval" > Events (in milliseconds) </param>
5///<param Name= "action" > Expression to execute </param>
6 public static void settimeout (double interval, action action)
7 {
8 System.Timers.Timer Timer = new System.Timers.Timer (interval);
9 timer. Elapsed + = Delegate (object sender, System.Timers.ElapsedEventArgs e)
10 {
One timer. Enabled = false;
Action ();
13};
Timer. Enabled = true;
15}
///<summary>
17///The specified expression repeatedly during the specified time period
///</summary>
The elapsed time (in milliseconds) between the///<param name= "Interval" > Events </param>
///<param name= "action" > Expression to execute </param>
public static void SetInterval (double interval, action<elapsedeventargs> Action)
22 {
System.Timers.Timer Timer = new System.Timers.Timer (interval);
Timer. Elapsed + = Delegate (object sender, System.Timers.ElapsedEventArgs e)
25 {
Action (e);
27};
Timer. Enabled = true;
29}
3.
Because System.Timers.Timer is "server-based Timer designed for worker threads in a multithreaded environment," If you want to modify the UI object when used in WinForm, give an example to use in WinForm:
Operation Effect: