using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace C_Sharp_thread
{
class Program
{
static void Main(string[] args)
{
Thread thread = Thread.CurrentThread;
thread.Name = "我是主线程!";
int thread_id = thread.ManagedThreadId;
ThreadState state = thread.ThreadState;
ThreadPriority priority = thread.Priority;
Console.WriteLine("name: {0}\n"+"id: {1}\n" + "state: {2}\n" + "priority: {3}\n", thread.Name,thread_id,state,priority);
//开启辅助线程1
Thread t1 = new Thread(show_Msg);
t1.Start();
//开启辅助线程2
Thread t2 = new Thread(show_Msg2);
t2.Start();
//开启辅助线程3
Thread t3 = new Thread(new ThreadStart(show_Y));
t3.IsBackground=true;
//在主线程中的for循环
for (int i = 0; i < 10; i++)
{
Console.WriteLine("我是主线程里面的for循环");
Thread.Sleep(300);
}
Console.ReadKey();
}
static void show_Msg()//在辅助线程1上运行的方法
{
for (int i=0;i<10;i++)
{
Console.WriteLine("我是辅助线程1上的for循环");
Thread.Sleep(300);
}
}
static void show_Msg2()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("我是辅助线程2上的for循环");
Thread.Sleep(300);
}
}
}
}