I have been searching for information and couldn't find any. My question is how to start DispatcherTimer from N seconds or minutes or hours. I mean currently it starts from 00:00:00 (also displayed in CurrentTime Label) but if I would like to start it from 00:00:30 (also display in CurrentTime Label), what should be differently?
To clarify it more... When I start an application I execute StartWorkingTimeTodayTimer(). Then I have a Label (CurrentTime) that is starting to show time of application runtime. Currently it starts from 00:00:00. I would like to display for example 00:00:30 at Start and then tick by one second as it is right now... so 00:00:30 -> 00:00:31 -> 00:00:32 -> 00:00:33 -> 00:00:34 ->
I have tried to play with:
DateTime x30SecsLater = StartTimeWholeDay.AddSeconds(30); without success.
Current code:
private static DateTime StartTimeWholeDay; private DispatcherTimer _dailyTimer; public void StartWorkingTimeTodayTimer() { StartTimeWholeDay = DateTime.Now; DateTime x30SecsLater = StartTimeWholeDay.AddSeconds(30); _dailyTimer = new DispatcherTimer(DispatcherPriority.Render); _dailyTimer.Interval = TimeSpan.FromSeconds(1); _dailyTimer.Tick += (sender, args) => { CurrentTime = (DateTime.Now - StartTimeWholeDay).ToString(@"hh\:mm\:ss"); // DateTime.Now.ToLongTimeString() }; _dailyTimer.Start(); } EDIT:
I have tried already:
public void StartWorkingTimeTodayTimer() { StartTimeWholeDay = DateTime.Now; DateTime x30SecsLater = StartTimeWholeDay.AddSeconds(30); _dailyTimer = new DispatcherTimer(DispatcherPriority.Render); _dailyTimer.Interval = TimeSpan.FromSeconds(1); _dailyTimer.Tick += (sender, args) => { CurrentTime = (DateTime.Now - x30SecsLater).ToString(@"hh\:mm\:ss"); // DateTime.Now.ToLongTimeString() }; _dailyTimer.Start(); } but it calculates backwards...
It should go the other way 00:00:30 -> 00:00:31 -> 00:00:32 -> 00:00:33 -> 00:00:34 ->

Task.Delaybefore the timer start?CurrentTimeto have an offset of 30 seconds?CurrentTime = (DateTime.Now - x30SecsLater).<etc>... that would start at "-30 seconds"... gives a hint.