Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Aktualny czas: {0}", DateTime.Now);
- new Alarm(10);
- Console.ReadKey();
- }
- }
- class Alarm
- {
- private DateTime _time;
- private Timer _alarm;
- public Alarm(int seconds)
- {
- _time = DateTime.Now.AddSeconds(seconds);
- _alarm = new Timer(1000);
- _alarm.Elapsed += new ElapsedEventHandler(checkAlarmTime);
- _alarm.Enabled = true;
- Console.WriteLine("Alarm został ustawiony na : {0}", this._time);
- }
- public int SetTime
- {
- set
- {
- this._time = DateTime.Now.AddSeconds(value);
- }
- }
- public DateTime GetTime
- {
- get
- {
- return this._time;
- }
- }
- private void checkAlarmTime(object sender, ElapsedEventArgs e) {
- if (e.SignalTime >= this._time)
- {
- Console.WriteLine("\n Alarm {0}", e.SignalTime);
- _alarm.Enabled = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement