Live Chat Icon For mobile
Live Chat Icon

How do I determine the time taken for a long operation that I perform?

Platform: WinForms| Category: Tips

You could use the DateTime.Ticks property to record the time taken for a long operation, as follows:


[C#]
		private void MyLongOp()
		{
			long startTicks = DateTime.Now.Ticks;

			// Perform a long op:

			long endTicks = DateTime.Now.Ticks;

			long delta = endTicks - startTicks;
			MessageBox.Show('Time taken in Ticks: ' + delta.ToString());
			delta = delta/(long)10000000;	// A tick is 100 nanoseconds
			MessageBox.Show('Time taken in seconds: ' + delta.ToString());
		}

[VB.Net]
		Private  Sub MyLongOp()
			Dim startTicks As Long =  DateTime.Now.Ticks 
 
			’ Perform a long op:
 
			Dim endTicks As Long =  DateTime.Now.Ticks 
 
			Dim delta As Long =  endTicks - startTicks 
			MessageBox.Show('Time taken in Ticks: ' + delta.ToString())
			delta = delta/(Long)10000000	’ A tick is 100 nanoseconds
			MessageBox.Show('Time taken in seconds: ' + delta.ToString())
		End Sub

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.