Timer tick problem
-
Hi, I have a timer that I want to run in the main frame of my windows HMI application to execute a complex operation. I chose a System.Windows.Forms.Timer timer so that it'll run on the main application thread. I added a tick event : this.timerPlot.Tick += new System.EventHandler(this.timerPlot_Tick); and the timer woks fine on calls to timerPlot.Start() and timerPlot.Enable=true. But... when I try to start the timer from a seperate thread in the application the timer function timerPlot_Tick is never called!!! Does anyone know the reason why a timer can not be started from a sperate thread? Thanks. avivhal
-
Hi, I have a timer that I want to run in the main frame of my windows HMI application to execute a complex operation. I chose a System.Windows.Forms.Timer timer so that it'll run on the main application thread. I added a tick event : this.timerPlot.Tick += new System.EventHandler(this.timerPlot_Tick); and the timer woks fine on calls to timerPlot.Start() and timerPlot.Enable=true. But... when I try to start the timer from a seperate thread in the application the timer function timerPlot_Tick is never called!!! Does anyone know the reason why a timer can not be started from a sperate thread? Thanks. avivhal
As MSDN states: "This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread." Use one of the other two
Timer
types. Here you find a short overview on timers.