What are the threads in a console application?

I use this code snippet below to view streams in the main console application.

lock (threadLock)
{
    ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads;
    foreach (ProcessThread thread in currentThreads)
    {
        Console.WriteLine(" Id={0}, CurrentPriority={1}, State={2}",
                          thread.Id, thread.CurrentPriority, thread.ThreadState);
    }
}

There are six threads. Below is the original output.

Id=2924, CurrentPriority=8, State=Running
Id=8900, CurrentPriority=8, State=Wait
Id=524, CurrentPriority=8, State=Wait
Id=4916, CurrentPriority=8, State=Wait
Id=5124, CurrentPriority=8, State=Wait
Id=6780, CurrentPriority=11, State=Wait

Apparently, the first thread is the main thread. The latter, with CurrentPriority = 11, is the Finalizer stream, because below is the output when launched inside the destructor:

Id=2924, CurrentPriority=8, State=Wait
Id=8900, CurrentPriority=8, State=Wait
Id=524, CurrentPriority=8, State=Wait
Id=4916, CurrentPriority=8, State=Wait
Id=5124, CurrentPriority=8, State=Wait
Id=6780, CurrentPriority=11, State=Running

. . (GC). -, , Threadpool. ? , ? GC- ? Finalizer GC, , . , .

+4

Source: https://habr.com/ru/post/1687074/


All Articles