Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _05.TimerDelegates
  9. {
  10. // Declare delegate
  11. public delegate void SampleDelegate();
  12.  
  13. public class Timer
  14. {
  15. // Fields
  16. private int timesOfExecute;
  17. private int Interval;
  18. private SampleDelegate timerDelegate;
  19.  
  20. // Constructor
  21. public Timer(SampleDelegate timerDelegate, int timesOfExecute, int Interval)
  22. {
  23. this.timerDelegate = timerDelegate;
  24. this.timesOfExecute = timesOfExecute;
  25. this.Interval = Interval;
  26. }
  27.  
  28. // Properties
  29. public int TimesOfExecute
  30. {
  31. get { return this.timesOfExecute; }
  32. set { this.timesOfExecute = value; }
  33. }
  34.  
  35. public int IntervalOfMilliseconds
  36. {
  37. get { return this.Interval; }
  38. set { this.Interval = value; }
  39. }
  40.  
  41. public SampleDelegate TimerDelegate
  42. {
  43. get { return this.timerDelegate; }
  44. set { this.timerDelegate = value; }
  45. }
  46.  
  47. // Methods
  48. // Start timer
  49. public void TimerExecute()
  50. {
  51. for (int i = 0; i < TimesOfExecute; i++)
  52. {
  53. Thread.Sleep(Interval);
  54. TimerDelegate();
  55. }
  56. }
  57.  
  58. // Print something
  59. public static void Print()
  60. {
  61. Console.WriteLine("Hello world!");
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement