Paul Williams
Paul Williams

Reputation: 1598

VB.Net: Combining Stopwatch values

I currently have two stopwatches ( running in a VB 2010 program. What I would like to do is combine their values together and have their results outputted in a string formatted as 0:00:00.

I tried the Add method and the + method but this fails.

This is in short what I have:

Dim timer1 As New Stopwatch
Dim timer2 As New Stopwatch

[Assuming the timers were started separately]

Dim elapsed1 As TimeSpan = timer1.Elapsed
Dim elapsed2 As TimeSpan = timer2.Elapsed

elapsed1 += elapsed2

Can anyone help?

Upvotes: 0

Views: 540

Answers (1)

John Woo
John Woo

Reputation: 263733

add this:

Dim elapsed3 As TimeSpan = elapsed1.Add(elapsed2)

or read from MSDN TimeSpan.Add Method

Upvotes: 1

Related Questions