Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

timer

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.

like image 563
kartal Avatar asked Dec 13 '22 11:12

kartal


2 Answers

Are you looking for the Stopwatch class?

using System.Diagnostics;

// ...

var stopwatch = Stopwatch.StartNew();
// ...
var milliseconds = stopwatch.ElapsedMilliseconds;
like image 155
Cameron Avatar answered Feb 12 '23 14:02

Cameron


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

like image 44
Klinger Avatar answered Feb 12 '23 16:02

Klinger