To test this theory I wrote this code:
What it does it starts the stopwatch and appends the elapsedmilliseconds to a multiline textbox until 2 seconds have passed. Even though it is a really small loop I noticed 2 very important things. The first data written is 1913, which means the 2 seconds are almost up before the "while" completes the first loop! the second thing is that some numbers repeat, sometimes more than twice (like the 1914) but then some are skipped (1927) which tell me that performance of the code decreases while the textbox is being filled and in that case is not reliable to try to catch a specific milisecond.Code:Dim stwTimer As Stopwatch = Stopwatch.StartNew() Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click stwTimer.Start() While stwTimer.ElapsedMilliseconds < 2000 TextBox1.AppendText(stwTimer.ElapsedMilliseconds.ToString & vbCrLf) End While stwTimer.Stop() End Sub
Here's a partial output of the code:
1913
1914
1914
1914
1915
1915
1916
1916
1917
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1928
1929
1930




Reply With Quote