Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace _05.TimerDelegates
- {
- // Declare delegate
- public delegate void SampleDelegate();
- public class Timer
- {
- // Fields
- private int timesOfExecute;
- private int Interval;
- private SampleDelegate timerDelegate;
- // Constructor
- public Timer(SampleDelegate timerDelegate, int timesOfExecute, int Interval)
- {
- this.timerDelegate = timerDelegate;
- this.timesOfExecute = timesOfExecute;
- this.Interval = Interval;
- }
- // Properties
- public int TimesOfExecute
- {
- get { return this.timesOfExecute; }
- set { this.timesOfExecute = value; }
- }
- public int IntervalOfMilliseconds
- {
- get { return this.Interval; }
- set { this.Interval = value; }
- }
- public SampleDelegate TimerDelegate
- {
- get { return this.timerDelegate; }
- set { this.timerDelegate = value; }
- }
- // Methods
- // Start timer
- public void TimerExecute()
- {
- for (int i = 0; i < TimesOfExecute; i++)
- {
- Thread.Sleep(Interval);
- TimerDelegate();
- }
- }
- // Print something
- public static void Print()
- {
- Console.WriteLine("Hello world!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement