using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Base14
{
class Program
{
static void Main(string[] args)
{
#region 给线程取名字
//Thread.CurrentThread.Name = "当前运行的线程";//Thread.CurrentThread.Name
//Console.WriteLine(Thread.CurrentThread.Name);
#endregion
#region IsBackground 判断是否是后台类型
//Console.WriteLine(Thread.CurrentThread.IsBackground);
//Console.ReadKey();
#endregion
#region 获取当前正在被执行的进程
//Console.WriteLine(Process.GetCurrentProcess().ProcessName);
//Console.ReadKey();
#endregion
#region 获取到输出当前环境下所有的进程
//foreach (Process item in Process.GetProcesses())
//{
// Console.WriteLine(item.ProcessName);
//}
//Console.ReadKey();
#endregion
#region 通过命令打开进程 ie
//foreach (Process item in Process.GetProcesses())
//{
// if (item.ProcessName.Contains("ie"))
// {
// Console.WriteLine(item.ProcessName);
// }
//}
//Console.ReadKey();
//Process.Start("iexplore","http://www.baidu.com");
#endregion
#region 挂起、唤醒
//ThreadStart ts = new ThreadStart(Show);//ThreadStart 委托
//Thread myThread = new Thread(ts);
//myThread.Name = "newThread";
//myThread.Start();//执行本线程
//myThread.Abort();//终止本线程
挂起 先不执行
//myThread.Suspend();
//Console.WriteLine("哈哈哈");
唤醒 执行线程
//myThread.Resume();
//Console.ReadKey();
#endregion
#region 销毁线程
//Thread mythread = new Thread(ThreadMethod);
//mythread.Start();
//Thread.Sleep(2000);
//mythread.Abort();
//Console.ReadKey();
#endregion
#region 创建线程
//Thread mt = new Thread(ThreadMethod);
//mt.Start("我是一个参数");
//Console.ReadKey();
#endregion
#region 域
//Console.WriteLine(Thread.GetDomain().FriendlyName);
//Console.WriteLine(Thread.GetDomainID());
//Console.ReadKey();
#endregion
#region 中断
//Thread mt = new Thread(ThreadM);
//mt.Start();
//Thread.Sleep(200);
//mt.Interrupt();
//Thread.Sleep(200);
//mt.Join();
//Console.ReadKey();
#endregion
#region 线程同步
//Book book = new Book();
//Thread t1 = new Thread(book.Sale);
//t1.Name = "第一个线程";
//Thread t2 = new Thread(book.Sale);
//t2.Name = "第二个线程";
//t1.Start();
//t2.Start();
//Console.ReadKey();
#endregion
#region 确保生成无重复的数字
//for (int i = 0; i < 5; i++)
//{
// Thread thread = new Thread(MyRandom);
// thread.Start();
//}
//Console.ReadKey();
#endregion
#region 确保生成无重复的数字 长
//for (int i = 0; i < 5; i++)
//{
// Thread thread = new Thread(MyRandom1);
// thread.Start();
//}
//Console.ReadKey();
#endregion
}
#region Show()
//public static void Show()
//{
// Console.WriteLine("这是一个单独的线程");
//}
#endregion
#region Show1()
//public static void Show1()
//{
// Console.WriteLine("独立休眠5秒");
// Thread.Sleep(5000);
//}
#endregion
#region ThreadMethod()
//public static void ThreadMethod()
//{
// try
// {
// for (int i = 0; i < 10; i++)
// {
// Thread.Sleep(500);
// Console.WriteLine(i);
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine("执行的线程被强制终止");
// }
//}
#endregion
#region ThreadMethod(object objects)
//public static void ThreadMethod(object objects)
//{
// try
// {
// for (int i = 0; i < 10; i++)
// {
// Console.WriteLine(i);
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine("执行的线程被强制终止");
// }
//}
#endregion
#region ThreadM()
//public static void
//{
// try
// {
// for (int i = 0; i < 10; i++)
// {
// Thread.Sleep(100);
// Console.WriteLine(i);
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine("执行的线程被强制中断");
// }
//}
#endregion
#region MyRandom()
//public static void MyRandom()
//{
// Random r = new Random();
// int index = r.Next(0, 99);
// Console.WriteLine(index);
//}
#endregion
#region MyRandom1()
//public static void MyRandom1()
//{
// byte[] bytes = Guid.NewGuid().ToByteArray();
// int index = BitConverter.ToInt32(bytes, 0);
// if (index < 0)
// {
// //递归 自己调用自己
// MyRandom1();
// }
// else
// {
// Random r = new Random();
// Console.WriteLine(r.Next(index)/10000);
// }
//}
#endregion
}
}