How is NET 4.0 SpinWait method different to pre-4.0 SpinWait()?

情到浓时终转凉″ 提交于 2019-12-06 03:28:06

The struct System.Threading.SpinWait is new to .NET 4.0. The method System.Threading.Thread.SpinWait() exists since .NET 1.0.

Note that System.Threading.SpinWait internally calls System.Threading.Thread.SpinWait(). For further details see "Concurrent Programming On Windows" by Joe Duffy (chapter 14, section "Spin Waiting").

The System.Threading.SpinWait structure was introduced into .NET 4. The System.Threading.Thread.SpinWait method has been present since .NET 1.0.

From the docs for the SpinWait structure:

SpinWait is not generally useful for ordinary applications. In most cases, you should use the synchronization classes provided by the .NET Framework, such as Monitor. For most purposes where spin waiting is required, however, the SpinWait type should be preferred over the SpinWait method.

Note the part that says you shouldn't be using either of them in most cases :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!