一、不带参数的

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading; namespace AAAAAA
{
class AAA
{
public static void Main()
{
Thread t = new Thread(new ThreadStart(A));
t.Start(); Console.Read();
} private static void A()
{
Console.WriteLine("Method A!");
}
}
}

二、带一个参数的

由于ParameterizedThreadStart要求参数类型必须为object,所以定义的方法B形参类型必须为object。

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading; namespace AAAAAA
{
class AAA
{
public static void Main()
{
Thread t = new Thread(new ParameterizedThreadStart(B));
t.Start("B"); Console.Read();
} private static void B(object obj)
{
Console.WriteLine("Method {0}!",obj.ToString ()); }
}
}

三、带多个参数的  
  由于Thread默认只提供了这两种构造函数,如果需要传递多个参数,我们可以自己将参数作为类的属性。定义类的对象时候实例化这个属性,然后进行操作。

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading; namespace AAAAAA
{
class AAA
{
public static void Main()
{
My m = new My();
m.x = ;
m.y = ; Thread t = new Thread(new ThreadStart(m.C));
t.Start(); Console.Read();
}
} class My
{
public int x, y; public void C()
{
Console.WriteLine("x={0},y={1}", this.x, this.y);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading; namespace AAAAAA
{
class AAA
{
public static void Main()
{
My m = new My();
m.x = ;
m.y = ; Thread t = new Thread(new ThreadStart(m.C));
t.Start(); Console.Read();
}
} class My
{
public int x, y; public void C()
{
Console.WriteLine("x={0},y={1}", this.x, this.y);
}
}
}

四、利用结构体给参数传值。  
定义公用的public struct,里面可以定义自己需要的参数,然后在需要添加线程的时候,可以定义结构体的实例。

/结构体
struct RowCol
{
public int row;
public int col;
}; //定义方法
public void Output(Object rc)
{
RowCol rowCol = (RowCol)rc;
for (int i = ; i < rowCol.row; i++)
{
for (int j = ; j < rowCol.col; j++)
Console.Write("{0} ", _char);
Console.Write("\n");
}
}

线程Thread,有参数和参数的更多相关文章

  1. 线程池ThreadPoolExecutor、Executors参数详解与源代码分析

    欢迎探讨,如有错误敬请指正 如需转载,请注明出处 http://www.cnblogs.com/nullzx/ 1. ThreadPoolExecutor数据成员 Private final Atom ...

  2. JUC之线程池-三大方法-七大参数-四种拒绝策略

    线程池:重点 三大方法 七大参数 四种拒绝策略 使用池化技术的理由: 我们的程序伴随着创建销毁线程十分浪费资源, 所以使用线程池,先创建线程,随用随取,用完归还 简单来说就是节约了资源. 使用线程池的 ...

  3. Lua 学习笔记(九)协同程序(线程thread)

    协同程序与线程thread差不多,也就是一条执行序列,拥有自己独立的栈.局部变量和命令指针,同时又与其他协同程序共享全局变量和其他大部分东西.从概念上讲线程与协同程序的主要区别在于,一个具有多个线程的 ...

  4. 线程(thread)

    线程(thread): 现代操作系统引入进程概念,为了并发(行)任务 1.进程之间的这种切换代价很高 2.通信方式的代价也很大基本概念: 1.线程是比进程更小的资源单位,它是进程中的一个执行路线(分支 ...

  5. 线程 Thread Runnable 守护线程 join MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  6. 转:线程Thread (1)

    引言 1.理解多线程 2. 线程异步与线程同步 3.创建多线程应用程序 3.1通过System.Threading命名空间的类构建 3.1.1异步调用线程 3.1.2并发问题 3.1.3线程同步 3. ...

  7. [深入学习C#]C#实现多线程的方法:线程(Thread类)和线程池(ThreadPool)

    简介 使用线程的主要原因:应用程序中一些操作需要消耗一定的时间,比如对文件.数据库.网络的访问等等,而我们不希望用户一直等待到操作结束,而是在此同时可以进行一些其他的操作.  这就可以使用线程来实现. ...

  8. C#实现多线程的方法:线程(Thread类)和线程池(ThreadPool)

    简介 使用线程的主要原因:应用程序中一些操作需要消耗一定的时间,比如对文件.数据库.网络的访问等等,而我们不希望用户一直等待到操作结束,而是在此同时可以进行一些其他的操作.  这就可以使用线程来实现. ...

  9. C/C++ Muti-Thread多线程编程学习(之)线程Thread | 创建、运行、结束

    文章目录 前言 线程 Thread 创建线程 CreateThread _beginthread _beginthreadex pthread_create 线程运行 结束线程 前言   多线程(Mu ...

  10. x264中重要结构体参数解释,参数设置,函数说明 <转>

    x264中重要结构体参数解释http://www.usr.cc/thread-51995-1-3.htmlx264参数设置http://www.usr.cc/thread-51996-1-3.html ...

随机推荐

  1. Microsoft Visual C++

    Microsoft Visual C++ Visual C++ 1.0 1992 Visual C++ 1.5 Visual C++ 2.0 (备注) Visual C++ 4.0 Visual C+ ...

  2. web框架思考

    以前一直不明白web框架是怎样实现路由.orm.接受请求的.今天看了下廖雪峰的python 实现web框架博客才明白. 简单总结并记录: http请求->wsgi->处理请求->返回 ...

  3. swf格式文件如何修改里面的动作路径或者动作脚本(没有源文件的情况)

    一.UrlActionEditor汉化版,这个工具是非常的简单和使用,直接把你需要需要修改的swf格式的flash文件在这里面打开 二.如果需要更加详细的修改可以下载一个SWFDecompiler4. ...

  4. CentOS7 监控进程网络流量工具安装

    服务器在做测试的时候,需要监控网络流量,用来了解在不同人数的时候服务器的网络使用量. 我们使用服务器环境是centos7,centos下通常使用iftop,或者nethogs来进行网络流量监控.这2个 ...

  5. 批量过滤POST GET数据

    if(get_magic_quotes_gpc()){ $_GET = stripslashes_array($_GET); $_POST = stripslashes_array($_POST); ...

  6. Lua table库整理(v5.1)

    这个库提供了表处理的通用函数. 所有函数都放在表 table. 无论何时,若一个操作需要取表的长度, 这张表必须是一个真序列. table.concat(list, [, sep, [, i , [, ...

  7. setTimeout的应用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 修改oracle实例名orcl为demo

    修改oracle实例名有六步: 1.sqlplus username/password as sysdba登陆,然后从spfile文件创建pfile文件 :create pfile from spfi ...

  9. Python检测IP合法 是否为公网IP

    判断IP 格式是否正确 def check_value(self, ipaddr): '''检查IP是否合法 :param ipaddr: string :return True ''' addr=i ...

  10. jsp连接SQL Server数据库的方式

    方式1:JDBC连接方式 Connection conn = null; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDrive ...