是Stopwatch.ElapsedTicks线程? [英] Is Stopwatch.ElapsedTicks threadsafe?
问题描述
如果我有一个共同的 System.Diagnostics.Stopwatch
例如,可以将多个线程调用 shared.ElapsedTicks
在安全的方式,并得到准确的结果?
If I have a shared System.Diagnostics.Stopwatch
instance, can multiple threads call shared.ElapsedTicks
in a safe manner and get accurate results?
有没有线程安全方面的任何区别/用秒表的共享实例以这种方式,而使用静态的精度 GetTimeStamp()
方法?
Is there any difference in terms of thread-safety/accuracy between using a shared instance of Stopwatch in this way, and using the static GetTimeStamp()
method?
我测量周围180ms的时间间隔,并发现使用共享实例给我更大的成果传播,包括那些比我矮所期望的显著数量。
I'm measuring intervals of around 180ms, and finding that using the shared instance is giving me a larger spread of results, including a significant number that are shorter than I would expect.
本机具有多个CPU(2 *英特尔X5550为它的价值)
The machine has multiple CPUs (2 * Intel X5550 for what it's worth)
推荐答案
从的 MSDN 的:任何实例成员不能保证是线程安全的
From MSDN: "Any instance members are not guaranteed to be thread safe."
这篇关于是Stopwatch.ElapsedTicks线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!