Is there a way to syncronize the start of multiple Stopwatch instances?
This seemingly simple task is causing me a minor headache.
1. In theory, one StopWatch should suffice, and your app can read its
current value (eg Elapsed, ElapsedMilliseconds) in the multiple cases you
have. If multi-threading, you may need appropriate precautions.
2. After writing the above, I tried an experiment that seemed to work. You
make a class that inherits from StopWatch, and that exposes MemberwiseClone,
as follows:
Public Class SwClone
Inherits Stopwatch
Implements ICloneable
Public Function Clone() As Object Implements System.ICloneable.Clone
Return MemberwiseClone()
End Function
End Class
You use it as follows:
Dim sw1 As New SwClone
sw1.Start()
System.Threading.Thread.Sleep(1000) ' let 1 sec pass to prove it worked
Dim sw2 As SwClone = CType(sw1.Clone, SwClone)
At this point, i think sw2 is a running clone of sw1 with 1 sec already
elapsed, and I think they are different objects. I slapped this together
without a lot of checking - if you want to use it, you better validate my
claims.