SpinWait Método (Int32)
Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Thread.SpinWait (Método) (Int32)

 

Hace que un subproceso espere el número de veces definido por el parámetro iterations.

Espacio de nombres:   System.Threading
Ensamblado:  mscorlib (en mscorlib.dll)

[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, 
	ExternalThreading = true)]
public static void SpinWait(
	int iterations
)

Parámetros

iterations
Type: System.Int32

Entero de 32 bits con signo que define la cantidad de tiempo de espera de un subproceso.

The M:System.Threading.Thread.SpinWait(System.Int32) method is useful for implementing locks. Classes in the .NET Framework, such as T:System.Threading.Monitor and T:System.Threading.ReaderWriterLock, use this method internally. M:System.Threading.Thread.SpinWait(System.Int32) essentially puts the processor into a very tight loop, with the loop count specified by the iterations parameter. The duration of the wait therefore depends on the speed of the processor.

Contrast this with the M:System.Threading.Thread.Sleep(System.Int32) method. A thread that calls M:System.Threading.Thread.Sleep(System.Int32) yields the rest of its current slice of processor time, even if the specified interval is zero. Specifying a non-zero interval for M:System.Threading.Thread.Sleep(System.Int32) removes the thread from consideration by the thread scheduler until the time interval has elapsed.

SpinWait is not generally useful for ordinary applications. In most cases, you should use the synchronization classes provided by the .NET Framework; for example, call Monitor.Enter or a statement that wraps Monitor.Enter (lock in C# or SyncLock in Visual Basic).

System_CAPS_cautionPrecaución

In the rare case where it is advantageous to avoid a context switch, such as when you know that a state change is imminent, make a call to the M:System.Threading.Thread.SpinWait(System.Int32) method in your loop. The code M:System.Threading.Thread.SpinWait(System.Int32) executes is designed to prevent problems that can occur on computers with multiple processors. For example, on computers with multiple Intel processors employing Hyper-Threading technology, M:System.Threading.Thread.SpinWait(System.Int32) prevents processor starvation in certain situations.

.NET Framework
Disponible desde 1.1
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Volver al principio
Mostrar:
© 2016 Microsoft