Using a TimeSpan as a Timer Interval

两盒软妹~` 提交于 2019-12-11 00:38:34

问题


How can I use the value of a TimeSpan as the interval for a Timer?


回答1:


Get the total milliseconds from the TimeSpan to use in the constructor for Timer:

var timer = new Timer(someTimeSpanObject.TotalMilliseconds);



回答2:


From: http://msdn.microsoft.com/en-us/library/system.timespan.totalmilliseconds.aspx

TimeSpan interval = new TimeSpan(1, 15, 42, 45, 750); 
Console.WriteLine("Value of TimeSpan: {0}", interval);
Console.WriteLine("{0:N5} seconds, as follows:", interval.TotalMilliSeconds);

You can set .TotalMilliSeconds to your Interval property.



来源:https://stackoverflow.com/questions/17123265/using-a-timespan-as-a-timer-interval

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!