How to create a stopwatch in c#? : <p>How to create a stopwatch in c# (visual studio 2012)that starts when you start typing in a a text box and stops when enter is pressed? It should start again when i start typing another word and end again on pressing enter, then display the times recorded for each word. </p>

<p>The following example demonstrates how to use the Stopwatch class to determine the execution time for an application.
C#</p>

<pre><code>using System;
using System.Diagnostics;
using System.Threading;
class Program
{
    static void Main(string[] args)
    {
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        Thread.Sleep(10000);
        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value.
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine("RunTime " + elapsedTime);
    }
}
</code></pre>
