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/1/1A7R//+D8YDFal+Wr/5M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F9qXnPM/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的区别的更多相关文章

  1. C# 最基本的涉及模式(单例模式) C#种死锁:事务(进程 ID 112)与另一个进程被死锁在 锁 | 通信缓冲区 资源上,并且已被选作死锁牺牲品。请重新运行该事务,解决方案: C#关闭应用程序时如何关闭子线程 C#中 ThreadStart和ParameterizedThreadStart区别

    C# 最基本的涉及模式(单例模式) //密封,保证不能继承 public sealed class Xiaohouye    { //私有的构造函数,保证外部不能实例化        private  ...

  2. ThreadStart和ParameterizedThreadStart区别

    ThreadStart: ThreadStart这个委托定义为void ThreadStart(),也就是说,所执行的方法不能有参数. ThreadStart threadStart=new Thre ...

  3. C# ThreadStart和ParameterizedThreadStart区别

    ThreadStart: ThreadStart这个委托定义为void ThreadStart(),也就是说,所执行的方法不能有参数.ThreadStart threadStart=new Threa ...

  4. C#中 ThreadStart和ParameterizedThreadStart区别

    最主要区别: 1.Thread 是启动一个线程,但是没有参数. 2.ParameterThreadStart  线程可以接受一个输入参数 ThreadStart: ThreadStart这个委托定义为 ...

  5. 多线程之 ThreadStart 和 ParameterizedThreadStart 委托

    先看微软如何给出的方法使用,如下查看,我们发现,如下两个委托,分别对应带参数创建线程 和 不带参数创建线程. 下列 委托 方法不带参数 ThreadStart namespace System.Thr ...

  6. 在C#中ParameterizedThreadStart和ThreadStart区别

    不需要传递参数,也不需要返回参数 我们知道启动一个线程最直观的办法是使用Thread类,具体步骤如下: ThreadStart threadStart=new ThreadStart(Calculat ...

  7. C#的ThreadStart 和 Thread

    多线程,new Thread(t1);和new Thread(new ThreadStart(t1));有什么区别 没有区别. 前者,是c#的语法.也就是说是编译器帮你改写为第二种形式. 因此你要搞清 ...

  8. C#编程总结(二)多线程基础

    C#编程总结(二)多线程基础 无论您是为具有单个处理器的计算机还是为具有多个处理器的计算机进行开发,您都希望应用程序为用户提供最好的响应性能,即使应用程序当前正在完成其他工作.要使应用程序能够快速响应 ...

  9. C#多线程操作界面控件的解决方案(转)

    C#中利用委托实现多线程跨线程操作 - 张小鱼 2010-10-22 08:38 在使用VS2005的时候,如果你从非创建这个控件的线程中访问这个控件或者操作这个控件的话就会抛出这个异常.这是微软为了 ...

随机推荐

  1. 隐藏NavigationBar的正确方式

    -(void)viewWillAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:YES animate ...

  2. python之登录小程序

    # 登录操作 PassWord_list = [] Reset_pw = '*#*#' def account_login(): if PassWord_list == []: PassWord = ...

  3. hg0088新2网址:已经做好了封装直接拿来就能用功能齐全

    很简单,InkCanvas就不用多介绍了,它是一个面板,特点是你可以在它上面涂抹,就像大街上那些妖怪那样,把化妆品往脸上乱涂,涂得人不像人,鸡不像鸡. InkToolBar呢是一个现成的工具栏,你可以 ...

  4. dos 批处学习笔记

    dos 批处理@ 只显示命令结果echo 回显pause 暂停del 删除set 查看系统变量>nul 正确命令输入空洞2>nul 错误命令输入空洞dir 显示目录和文件&& ...

  5. CMake

    使用CMake编译跨平台静态库 http://www.tuicool.com/articles/3uu2Yj cmake命令 安装.用法简介 https://fukun.org/archives/04 ...

  6. 简单的RPC原型与实现原理

    存在的问题 客户端硬编码服务端的地址 引入注册中心,方便服务的注册与发现 注册中心记录的信息:服务地址列表&服务节点权重 Zookeeper节点类型 临时节点:客户端.. 服务注销: tomc ...

  7. CDCE913产生任意频率

    1,上TI官网下载CDCE913的datasheet和配置软件clock Pro.如果只需要配置CDCE913成某一个固定频率,那么用clock Pro可以很方便快捷. TI的初衷应该就是通过I2C配 ...

  8. Velocity 局部定制模板

    Velocity介绍 Velocity是一个基于java的template engine.它允许Web designer引用Java Code中定义的方法.Web designer可以和Java工程师 ...

  9. sql注入时易被忽略的语法技巧以及二次注入

    那些容易被忽略.容易被弄错的地方 sql注入时的技巧 ========================================================================= ...

  10. bind绑定参数

    const curry = (fn) => (...args)=>fn.bind(null,...args); const split = curry((splitOn, str) =&g ...