syncronized start

  • Thread starter Thread starter Craig Buchanan
  • Start date Start date
C

Craig Buchanan

Is there a way to syncronize the start of multiple Stopwatch instances?
This seemingly simple task is causing me a minor headache.

Thanks,

Craig Buchanan
 
Craig said:
Is there a way to syncronize the start of multiple Stopwatch
instances? This seemingly simple task is causing me a minor headache.

I'd say no. Why can't you use single Stopwatch? What's your intention?


Armin
 
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.
 
Originally, my goal was to create a UI of multiple stopwatches, to replace
the need to hold multiple, physical stopwatches (think of timing multiple
individuals in a race).

At the push of a button, multiple stopwatches could be started (in a loop).
The code would execute rapidly enough to give the illusion that the
stopwatches started at the same time (assuming 1/10 or 1/100 of a second
resolution).

Then I started to wonder how this situation would be handled if I really did
need multiple stopwatches with high resolution. It isn't as trivial as I
thought initially.

Thoughts?

Thanks.
 
Originally, my goal was to create a UI of multiple stopwatches, to replace
the need to hold multiple, physical stopwatches (think of timing multiple
individuals in a race).

At the push of a button, multiple stopwatches could be started (in a loop).
The code would execute rapidly enough to give the illusion that the
stopwatches started at the same time (assuming 1/10 or 1/100 of a second
resolution).

Then I started to wonder how this situation would be handled if I really did
need multiple stopwatches with high resolution. It isn't as trivial as I
thought initially.

Thoughts?

Thanks.
 
Originally, my goal was to create a UI of multiple stopwatches, to replace
the need to hold multiple, physical stopwatches (think of timing multiple
individuals in a race).

At the push of a button, multiple stopwatches could be started (in a loop).
The code would execute rapidly enough to give the illusion that the
stopwatches started at the same time (assuming 1/10 or 1/100 of a second
resolution).

Then I started to wonder how this situation would be handled if I really did
need multiple stopwatches with high resolution. It isn't as trivial as I
thought initially.

Thoughts?

Thanks.
 
Craig said:
Originally, my goal was to create a UI of multiple stopwatches, to
replace the need to hold multiple, physical stopwatches (think of
timing multiple individuals in a race).

At the push of a button, multiple stopwatches could be started (in a
loop). The code would execute rapidly enough to give the illusion
that the stopwatches started at the same time (assuming 1/10 or 1/100
of a second resolution).

You could use a USB relay controller, e.g.
http://www.relaycontrollers.com/mm5/merchant.mvc?Screen=CTGY&Store_Code=NCD&Category_Code=USB_Relays

with solenoids to operate the buttons on the stopwatches.
Then I started to wonder how this situation would be handled if I
really did need multiple stopwatches with high resolution. It isn't
as trivial as I thought initially.

I think you'd be better off trying whatever programming you find simplest
and seeing if that is sufficient. But depending on what you mean by high
resolution, using a computer for the timing might not be good enough.
http://icanhascheezburger.com/2008/07/21/funny-pictures-5-hrs-42-min/

Andrew
 
Armin-

I am creating stopwatches w/ a UI for the purpose of timing races. Each
stopwatch is meant to track an individual racer. The stopwatches need to
start at the same time, but will most likely finish independently.

At this point, I use a button to loop thru each stopwatch class (a wrapper
around the System.Diagnostics.Stopwatch) , calling each of my class' Start
method.

While this works for the most part, I've noticed that there can be a
difference between the times of the 1st and nth stopwatch--usually 1-2
hundreths of a second. I attribute this to the time it takes to start each
stopwatch in a loop.

I would like to be able to syncronize the start of these stopwatches w/
great accuracy.

Thoughts?

Thanks.
 
Back
Top