开发者

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

开发者 https://www.devze.com 2023-03-19 16:30 出处:网络
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 y

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

精彩评论

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