dispatchertimer

send a extra argument in Dispatchertimer.Tick event

╄→尐↘猪︶ㄣ 提交于 2019-12-05 05:49:38
my question is how can i send some arguments in Dispatchertimer.Tick event here is the code: what i wanted to is receive a integer value at dispatcheTimer_Tick dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); private void dispatcherTimer_Tick(object sender, EventArgs e) { //.Text = DateTime.Now.Second.ToString(); } what i wanted to do is something like this private void dispatcherTimer_Tick(object sender, EventArgs e,int a) { //.Text = DateTime.Now.Second.ToString(); } how to send a value from a calling point?? While there are a number of ways, I find it most convenient to use

Will this Timer be released from memory?

戏子无情 提交于 2019-12-05 03:01:00
Consider this pair of functions in C#: void func1() { DispatcherTimer tmr = new DispatcherTimer(); tmr.Interval = TimeSpan.FromSeconds(5); tmr.Tick += func2; tmr.Start(); } void func2(object a, EventArgs b) { // Called every 5 seconds once func1() is called } After calling func1() once, func2() is called every 5 seconds from then on, even though I lose the reference to my timer since its scope is restricted to func1(). That means that the timer is obviously still in memory, doing its thing, long after func1() was called. My question is, if I add this to func2(): void func2(object a, EventArgs

Using ThreadPoolTimer with Background Audio UWP

巧了我就是萌 提交于 2019-12-04 20:22:36
I am making a UWP app using the BackgroundAudioTask. My app is working very well. Now I want to add in a TextBlock the Current position of the Audio played. I was doing this method before implementing the audio Task: private TimeSpan TotalTime; private DispatcherTimer timerRadioTime; private void radioPlayer_MediaOpened(object sender, RoutedEventArgs e) { TotalTime = radioPlayer.NaturalDuration.TimeSpan; // Create a timer that will update the counters and the time slider timerRadioTime = new DispatcherTimer(); timerRadioTime.Interval = TimeSpan.FromSeconds(1); timerRadioTime.Tick +=

Timer for traffic lights c#

做~自己de王妃 提交于 2019-12-02 13:23:37
i have wrote the code for a simple traffic light app with wpf elements. I use the timer function. The app works without any exception, but the wanted function isnt there. It only flashes the red or the orange light. I sit for 3 hours and now brain is empty. I try and try without any change. Can you help me please to fix the problem and learn how to use the timer correct? Thanks a lot using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System

WPF C# - Timer countdown

谁说胖子不能爱 提交于 2019-12-02 11:32:39
问题 How can I implement the following in my piece of code written in WPF C#? I have a ElementFlow control in which I have implemented a SelectionChanged event which (by definition) fires up a specific event when the control's item selection has changed. What I would like it to do is: Start a timer If the timer reaches 2 seconds then launch a MessageBox saying ("Hi there") for example If the selection changes before the timer reaches 2 seconds then the timer should be reset and started over again.

WPF C# - Timer countdown

℡╲_俬逩灬. 提交于 2019-12-02 07:24:31
How can I implement the following in my piece of code written in WPF C#? I have a ElementFlow control in which I have implemented a SelectionChanged event which (by definition) fires up a specific event when the control's item selection has changed. What I would like it to do is: Start a timer If the timer reaches 2 seconds then launch a MessageBox saying ("Hi there") for example If the selection changes before the timer reaches 2 seconds then the timer should be reset and started over again. This is to ensure that the lengthy action only launches if the selection has not changed within 2

DispatchTimer - Prevent the tick event to be triggered if the previous tick is still running

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 18:50:32
In a Silverlight app, I have a block of code that has to run every 500ms. I am planning o use a DispatcherTimer to achieve this (see code below). DispatcherTimer dt = new DispatcherTimer(); dt.Interval = new TimeSpan(0, 0, 0, 0, 500); // 500 Milliseconds dt.Tick += new EventHandler(dt_Tick); dt.Start(); However, it may happen that the block of code takes longer than 500ms to execute (the block of code does some webservice calls). How do I make sure that if a call is currently in progress, the DispatcherTimer doesn't trigger another event? What are the options and what is the best way? Using

how to make DispatcherTimer events smoother in WPF?

旧城冷巷雨未停 提交于 2019-11-30 19:27:06
In my WPF application, the user presses a button to start a 3D model rotating smoothly, and lets up on the button to stop the rotation. To do this, I create a DispatcherTimer: DispatcherTimer timer = new DispatcherTimer(); timer.Tick += new EventHandler( timer_Tick ); timer.Interval = new TimeSpan( 0, 0, 0, 0, 30 ); And when the button is pressed I call timer.Start() and when the button is let up I call timer.Stop() . The timer_Tick function changes the rotation of the model: void timer_Tick( object sender, EventArgs e ) { spin = ( spin + 2 ) % 360; AxisAngleRotation3D rotation = new

dispatch_source_cancel on a suspended timer causes EXC_BAD_INSTRUCTION

最后都变了- 提交于 2019-11-29 16:46:30
问题 I'm trying to cancel and then release a suspended timer but when I invoke 'dispatch_release' on it, I immediately get EXC_BAD_INSTRUCTION. Is this not a valid set of actions to take on a timer? Timer creation & suspension: @interface SomeClass: NSObject { } @property (nonatomic, assign) dispatch_source_t timer; @end // Class implementation @implementation SomeClass @synthesize timer = _timer; - (void)startTimer { dispatch_queue_t globalQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY

Async friendly DispatcherTimer wrapper/subclass

Deadly 提交于 2019-11-29 05:10:33
I have a DispatcherTimer running in my code that fire every 30 seconds to update system status from the server. The timer fires in the client even if I'm debugging my server code so if I've been debugging for 5 minutes I may end up with a dozen timeouts in the client. Finally decided I needed to fix this so looking to make a more async / await friendly DispatcherTimer. Code running in DispatcherTimer must be configurable whether it is reentrant or not (i.e. if the task is already running it should not try to run it again) Should be task based (whether or not this requires I actually expose