public TimerDeviceImpl(IProtocol protocol, ITimer timer = null) { _protocol = protocol; _currentPacket = null; if (timer == null) timer = new Timer(); _timer = timer; _timer.Elapsed += TimerForTimeouts_Elapsed; _protocol.IncomingData += ProtocolOnIncomingData; _stream = null; }
static void Main() { var timer = new Timer(); timer.Elapsed += timer_Elapsed; timer.Start(1000); var worker = new Worker(); var thread = new Thread(worker.Run); thread.Start(); Console.ReadKey(); }
public void Run() { _timer = new Timer(); _number = 0; _timer.Elapsed += delegate { var threadName = Thread.CurrentThread.ManagedThreadId; Console.WriteLine(@"Number " + threadName + @" " +_number); ++_number; if (_number >= 10) { Stop(); } }; _timer.Start(1000); _waiter.WaitOne(); }