ThreadStart 与ParameterizedThreadStart的区别
1) ParameterizedThreadStart与ThreadStart
1 static void Main(string[] args)
{ #region ParameterizedThreadStart第一种写法
Thread thread = new Thread(new ParameterizedThreadStart(
(s) => { Console.WriteLine(s.ToString());
} ));
thread.Start("45 1");
#endregion
#region ParameterizedThreadStart第二种写法
//把方法抽出WriteOut
ParameterizedThreadStart parThread = new ParameterizedThreadStart(WriteOut);//WriteOut是方法
Thread thread2 = new Thread(parThread);
thread2.Start("3433343 2"); #endregion #region ThreadStart第一种写法 Thread thread3 = new Thread(new ThreadStart(
() =>
{ Console.WriteLine("ThreadStart里是没有参数的方法 3");
} ));
thread3.Start();//no parameter
#endregion #region ThreadStart第2种写法 Thread thread4 = new Thread(
() =>
{ Console.WriteLine("ThreadStart里是没有参数的方法222 4");
} );
thread4.Start();//no parameter
#endregion
Console.ReadKey(); } private static void WriteOut(object obj)
{
Console.WriteLine(obj.ToString());
}
输出结果顺序是不定的。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAU8AAABjCAIAAACUthVcAAAKO0lEQVR4nO2bS3MURxLH6+NwkS/wHeDMmSMc9sonGDsctndjNxzsaX3bCDb2YB8Uge2wDX60wTK7ll+Ih0DID2xJsHrxkHyePUhqkqrMrKzq6hmm+v+LDEVPdlZWdlX9u0czU258xIkTJ8bj8aXFddZGr7356utvhfbGn//65l/efo14/vaPf7979b6UJ9VGp92x8wvGl6nZJmAZPdImky9YtoWzc+7khU4XODp9lGF+dMw5546fnV+/tLh+6cIZ55xzbaqLJ92Z0eLC2TnHMDcanT/uTl88yPnO+eNBxJnR9IdLHaWj6w1KvXjSOefacV44O3c0RC9MxGErZvDnR8fmRu/4BRymdZ7a3/92g7X56w/evbpisfeurV76Zk3Kk2j/OuVOnJs3vkzNNgFL73H+1WPuzGhqBSu2cO4Vd+rC1Id0Fq2nUUpO66v9g+82YNOy0WnnnDv19+lXwtnCuVde2tpgJvPV/uH3D2EwWJXmxuPxwVv6A7V/9MMjGAxWpT3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7sSap1XoblxXrWaPaM5Lgx3F9qXnPM/BoWdVENLyjsUqh9BR97HwhYkIcVJw+Sk5K6EIHdKVsgd5NacE9G3KndbrFazZ5T7qgDCXW5fnszvPZnfw/fzNS3JycXw1REWhMsnX3Jx8pis0igLXSkX0447l0tYIq+4krQ81Jaoiafze099nG9fZC4oJJCC8nFOlisnIXVsQf0NE9ISH0hNZ2aarJG1GxamVgbtcq6B7EXZamRcyPRdT+4SvOJKsuUlperm2cLeswW/93zyOMlsSuPaFnbcuYK+91iYVzMdie99deYnlFu4SCLaSVgcex3sNPt+2SVcP8K1cCvgvFjfYHpK2BL6uB553dqa0cW90cUAzheSfUWUE3k1qWyJPCVAlpDHnDJXK0g555UnlRM0zSgThK40atz9JQWN//11roYvwQWrZXRxf3RxH9/PFxKymcJZOyexkAVztcIUJHJXwlzOZgrkVxF0rkn54zKE0qmJ50v7z5f28f18zW3T3NfcovkKpt36tsGVcOsmZ9pLygULdFUs6Jw9R7F4YQJK1cSLpf0XS/n3fECidDLnH6VgRVVpmvOxwj0plGaTu+Jml8vLXDKgebm8/3IZzs9jb2uBtCRbbvw9nKrJ/rSrnHMJ5uQaIKfjjslTGtvLzWdXQ1584M2r5YNXywdwfknIPa3crAXizkiuAU3/pJOVc5GCykJle4VrAc3rNwev38D5AEQGnA9AjIytHIytwPkARMb4ysE4nA9AbEy8PZx4ewjnAxAXrbeHLTgfgNhovTtsvYPzAYiMydXDyVU4H4DImFo9mlo9gvMBiIvp1aNpOB+A2JheO5peg/MBiIyZtaMZOB+A2JhZP5pZh/MBiIzZ9ePZ9WM4H4C4mFs/noPzAYiNuffHc+/hfAAiY/798TycD0BswPkAxMjCxvHCBpwPQGTA+QDECJwPQIwsbHxY2PgA5wMQFf8BK03wW35mNj0AAAAASUVORK5CYII=" alt="" />
等等
2)ParameterizedThreadStart多个参数的传递
可以把多个值封装到一个类里进行传递
class Program
{
static void Main(string[] args)
{ ParameterizedThreadStart paraThread = new ParameterizedThreadStart(AddTwoNumber);
Thread thread = new Thread(paraThread);
Number numbers = new Number();
numbers.SetPare(, ); thread.Start(numbers);
Console.ReadKey(); } private static void AddTwoNumber(object obj)
{//这里传过来一个类
if (obj is Number)
{
Number num = (Number)obj;
Console.WriteLine(num.First + " +" + num.Second+"=" +(num.First+num.Second));
}
} } class Number
{
private int first;
private int second;
public int First
{ get
{ return first;} set
{ first = value;} }
public int Second
{
get { return second; }
set { second = value; }
} public void SetPare(int n, int m)
{
first = n;
second = m;
} }
ThreadStart 与ParameterizedThreadStart的区别的更多相关文章
- C# 最基本的涉及模式(单例模式) C#种死锁:事务(进程 ID 112)与另一个进程被死锁在 锁 | 通信缓冲区 资源上,并且已被选作死锁牺牲品。请重新运行该事务,解决方案: C#关闭应用程序时如何关闭子线程 C#中 ThreadStart和ParameterizedThreadStart区别
C# 最基本的涉及模式(单例模式) //密封,保证不能继承 public sealed class Xiaohouye { //私有的构造函数,保证外部不能实例化 private ...
- ThreadStart和ParameterizedThreadStart区别
ThreadStart: ThreadStart这个委托定义为void ThreadStart(),也就是说,所执行的方法不能有参数. ThreadStart threadStart=new Thre ...
- C# ThreadStart和ParameterizedThreadStart区别
ThreadStart: ThreadStart这个委托定义为void ThreadStart(),也就是说,所执行的方法不能有参数.ThreadStart threadStart=new Threa ...
- C#中 ThreadStart和ParameterizedThreadStart区别
最主要区别: 1.Thread 是启动一个线程,但是没有参数. 2.ParameterThreadStart 线程可以接受一个输入参数 ThreadStart: ThreadStart这个委托定义为 ...
- 多线程之 ThreadStart 和 ParameterizedThreadStart 委托
先看微软如何给出的方法使用,如下查看,我们发现,如下两个委托,分别对应带参数创建线程 和 不带参数创建线程. 下列 委托 方法不带参数 ThreadStart namespace System.Thr ...
- 在C#中ParameterizedThreadStart和ThreadStart区别
不需要传递参数,也不需要返回参数 我们知道启动一个线程最直观的办法是使用Thread类,具体步骤如下: ThreadStart threadStart=new ThreadStart(Calculat ...
- C#的ThreadStart 和 Thread
多线程,new Thread(t1);和new Thread(new ThreadStart(t1));有什么区别 没有区别. 前者,是c#的语法.也就是说是编译器帮你改写为第二种形式. 因此你要搞清 ...
- C#编程总结(二)多线程基础
C#编程总结(二)多线程基础 无论您是为具有单个处理器的计算机还是为具有多个处理器的计算机进行开发,您都希望应用程序为用户提供最好的响应性能,即使应用程序当前正在完成其他工作.要使应用程序能够快速响应 ...
- C#多线程操作界面控件的解决方案(转)
C#中利用委托实现多线程跨线程操作 - 张小鱼 2010-10-22 08:38 在使用VS2005的时候,如果你从非创建这个控件的线程中访问这个控件或者操作这个控件的话就会抛出这个异常.这是微软为了 ...
随机推荐
- selenium-----chromedriver与chrome版本映射
chromedriver下载地址:http://chromedriver.storage.googleapis.com/index.html chromedriver版本 支持的Chrome版本 v2 ...
- C#操作XML的通用方法总结
转载至http://www.cnblogs.com/pengze0902/p/5947997.html 1.创建xml 复制代码 /// <summary> /// 创建XML文档 /// ...
- Adapt适配器
为接口提供所有的空实现,让使用者仅仅覆盖需要的部分: 本思想肯定有问题,慢慢考究 frame.addWindowListener(new WindowAdapter() { @Override pub ...
- iOS 10、Xcode 8 遇到部分问题解决记录
今天把iphone 6 升级到ios10 后,用Xcode 7进行真机调试的时候提示: Could not find Developer Disk Image 果断准备升级到Xcode 8 .但是想保 ...
- 第三章 --- 关于Javascript 设计模式 之 代理模式
第一.定义: 代理模式是为一个对象提供代用品或者占位符,以便控制对它的访问. 比如说,某男生小明想向他的女神 A 表白,刚好小明认识的一个女生B 和 女神A 是好朋友,那么小明就想让 女生B 帮忙送花 ...
- Sql Server 学习链接
避免SQL全表查询:http://www.dedecms.com/knowledge/data-base/sql-server/2012/0821/11698.html?jdfwkey=n3nuq
- 如何将已部署在ASM的资源迁移到ARM中
使用过Azure的读者都知道,Azure向客户提供了两个管理portal,一个是ASM,一个是ARM,虽然Azure官方没有宣布说淘汰ASM,两个portal可能会在很长的一段时间共存,但是考虑到AR ...
- centos7 编译php56
编译安装php5.6 centos7环境 步骤: //下载php5.6 wget http://cn2.php.net/distributions/php-5.6.26.tar.bz2 //安装依赖 ...
- HTML CSS 特殊字符表(转载)
转载地址:http://blog.csdn.net/bluestarf/article/details/40652011 转载原文地址:http://zhengmifan.com/news/noteb ...
- css3 FlexBox 弹性布局
Flex 弹性布局 这个是css3中新添加的内容,现在已经支持所有的浏览器,利用Flex布局,可以简便.完整.响应式地实现各种页面布局. 注意:在设置 flex 后,子元素的flaot ,clear, ...