timer

Download Timer

If you can't read please download the document

Upload: huy-cuong-bui-cong

Post on 19-Dec-2015

215 views

Category:

Documents


1 download

DESCRIPTION

Timer

TRANSCRIPT

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Timers;

namespace OPC_project{ class Program { static void Main(string[] args) { device dv1 = new device(); dv1.a = 2; ConsoleKeyInfo key; do { key = Console.ReadKey(); dv1.Run(); if (key.Key == ConsoleKey.A) { Console.WriteLine("iloveyou"); } } while (key.Key != ConsoleKey.E);

} public class device { Timer timer = null; public int a ; public int i; public void Run() { timer = new Timer(300); timer.AutoReset = true; timer.Elapsed += new ElapsedEventHandler(UpdateTag); timer.Start(); } public void Stop() { if (timer != null) timer.Dispose(); } void UpdateTag(object obj, ElapsedEventArgs e) { a++; i++; Console.WriteLine(this.a.ToString()); }

} }}