开发者

two dispatchertimer events at the same time?

开发者 https://www.devze.com 2023-03-11 21:41 出处:网络
i have a wpf app that is updating date/time in one dispatchertimer, another is for a mp3 player timer that tracks time and slidebar for playing time.is it possible to have 2 dispatchertimer\'s running

i have a wpf app that is updating date/time in one dispatchertimer, another is for a mp3 player timer that tracks time and slidebar for playing time. is it possible to have 2 dispatchertimer's running?

that's dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); and dispatcherTimer.Tick += new EventHand开发者_开发知识库ler(mp3Timer_Tick);


Yes, it's possible.

What you are doing is something different: You are trying to attach two event handlers to one DispatcherTimer. Don't do that. If you want two timers for different purposes (and with different timeouts), use two DispatcherTimer objects:

dateTimeTimer.Tick += new EventHandler(dateTimeTimer_Tick); 
mp3Timer.Tick += new EventHandler(mp3Timer_Tick);

Then you can do something like...

mp3Timer.Stop();

...when the music stops playing, and it won't affect the dateTimeTimer.

0

精彩评论

暂无评论...
验证码 换一张
取 消