Leer en inglés

Compartir a través de


Thread.ThreadState Propiedad

Definición

Obtiene un valor que contiene los estados del subproceso actual.

C#
public System.Threading.ThreadState ThreadState { get; }

Valor de propiedad

Uno de los valores de ThreadState que indica el estado del subproceso actual. El valor inicial es Unstarted.

Ejemplos

En el ejemplo de código siguiente se muestra el ThreadState acceso a de un subproceso.

C#
using System;
using System.Threading;

class Example
{
    static void Main()
    {
        Thread newThread = 
            new Thread(new ThreadStart(ThreadMethod));

        Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
        newThread.Start();

        // Wait for newThread to start and go to sleep.
        Thread.Sleep(300);
        Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
        
        // Wait for newThread to restart.
        Thread.Sleep(1000);
        Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
    }

    static void ThreadMethod()
    {
        Thread.Sleep(1000);
    }
}
// The example displays the following output:
//       ThreadState: Unstarted
//       ThreadState: WaitSleepJoin
//       ThreadState: Stopped

Comentarios

La ThreadState propiedad proporciona información más específica que la IsAlive propiedad .

Importante

El estado del subproceso solo es de interés en escenarios de depuración. El código nunca debe usar el estado de los subprocesos para sincronizar las actividades de los subprocesos.

Se aplica a

Producto Versiones
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1