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.aspxThis 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");
精彩评论