开发者

Create timer and start it and get its value at anytime c#

I want to create a timer and 开发者_开发知识库start it and gets its value at any time in C# and I want to know what it is, depending on, for example, is it by seconds or milliseconds or so forth.


Are you looking for the Stopwatch class?

using System.Diagnostics;

// ...

var stopwatch = Stopwatch.StartNew();
// ...
var milliseconds = stopwatch.ElapsedMilliseconds;


Have you looked at Stopwatch class?

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

This is another link with some good examples: http://www.dotnetperls.com/stopwatch


var start = Environment.TickCount;
// loop for 2 seconds
while(Environment.TickCount-start <2000)
{
    Console.Write(".");
}
Console.WriteLine("done");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜