Dotnet creates threads and executes them

Net environment.The core 2.1.5

The core code

Thread thread = new Thread(TConsoleWrite); Thread.isbackground = true; thread.isbackground = true; Thread.start (); thread.start (); //Start starts the thread of executionCopy the code

Remember to write wait: otherwise the main thread will be released when it finishes running

Complete code:

using System; using System.Threading; Namespace netcore.thread.demo {class Program {static void Main(string[] args) {Console.WriteLine(" Start thread! "); // Create a thread and name it thread thread thread = new thread (TConsoleWrite); Thread.isbackground = true; thread.isbackground = true; Thread.start (); thread.start (); System.console. WriteLine(" Press CTRL + C to stop running "); While (true) {}} static void TConsoleWrite() {// The method in the executed thread outputs system.console. WriteLine(" thread-one output "); }}}Copy the code