Link to main thread in C #

How to get a link to the main thread from another thread in C #?

Why is this needed? Take, for example, the assembly loaded into the console application. This assembly raises another thread that wants to wait (join) to the main thread of the console application. How will he do it?

I thought about this: in Visual Studio 2010 you can check thread information during debugging. One of the columns in the stream window is a category that determines whether the stream is a work stream or a main stream. Is it possible to get this information?

Or like this: how to get the name of the function that is the entry point (main thread?), And repeat all the threads in the current process. How can I get this information?

Thank.

+3
source share
2 answers

You can keep a link to Thread.CurrentThread(which will be the main thread) when creating another thread.

+2
source

The thread is not really the main thread. After you create more threads, it will cease to be important, the main thing. The only way to find out which stream was created first is to store the link to it in some global static field.

+1
source

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


All Articles