线程的基本操作
2016-03-01 21:17
302 查看
namespace 线程的操作演示 { class Program { static void Main(string[] args) { //1.通过启动一个新线程执行一个无参数,无返回值的方法 Thread t = new Thread(new ThreadStart(M1)); t.IsBackground = true; t.Start(); //2.通过线程执行一个带一个参数的方法 Thread t = new Thread(new ParameterizedThreadStart(M2)); t.IsBackground = true; t.Start("hello"); //3.启动线程,执行带多个参数的方法 Person p = new Person(); p.Name = "小李"; p.Age = 17; p.Gender = "女"; Thread t = new Thread(new ThreadStart(p.Say)); t.IsBackground = true; t.Start(); //4.获取线程编号 Console.WriteLine("主线程的编号:" + Thread.CurrentThread.ManagedThreadId); //启动一个新线程 Thread t = new Thread(new ThreadStart(() => { Console.WriteLine("这是一个新线程,线程编号是:" + Thread.CurrentThread.ManagedThreadId); })); t.IsBackground = true; t.Start(); Console.WriteLine("ok"); Console.Read(); } static void M2(object obj) { Console.WriteLine(obj); } static void M1() { for (int i = 0; i < 100; i++) { Console.WriteLine(". "); } } } public class Person { public string Name { get; set; } public int Age { get; set; } public string Gender { get; set; } public void Say() { Console.WriteLine(this.Name + " " + this.Age + " " + this.Gender); } } }
相关文章推荐
- 2014新跟踪算法KCF笔记 --续(代码部分)
- POJ 1144 Network【割点个数】
- Java I/O 模型的演进
- 【eclipse】generate getters and setters错误
- android开发内存溢出处理记录
- hdu1565方格取数(1) (最大权独立集)
- android开发中Rsa加密的使用
- zTree -- jQuery 树插件
- 程序员思维修炼 --- 读书笔记(一)
- 全排列函数
- <深入理解Linux内核>--Linux源码步步为营 Unix内核概述
- linux 学习第四天
- 翻转子串(思路:假定两个字符串已经是翻转)
- 学习笔记:Ubuntu15.04 + Python 配置
- 悼念512汶川大地震遇难同胞——老人是真饿了 hdu 2187
- 蓝牙连接参数关于IOS的限制
- java常见基础知识汇总
- Android Service解析
- POJ3250 Bad Hair Day(单调栈)
- hdu 4146 Flip Game