C#线程调用有参和无参函数的方法
2014-01-03 15:25
288 查看
引用命名空间:using System.Threading;
一、调用无参函数
Thread th = new Thread(new ThreadStart(Function));
th.Start();
private static void Function()
{
//被线程调用的方法
}
二、调用有一个参数的函数
Thread th = new Thread(new ParameterizedThreadStart(Function));
th.Start("需要传递的参数");
private static void Function(object obj)
{
//被线程调用的方法
}
三、调用有多个参数的函数
MyClass m = new MyClass();
m.name = "佚玥";
m.age =24;
Thread th = new Thread(new ThreadStart(m.Function));
th.Start();
//自己定义的参数传递类
class MyClass
{
public string name;
public int age;
//自己需要的参数 都 设置 成 字段 或属性
public void Function()
{
//被线程调用的方法
}
}
一、调用无参函数
Thread th = new Thread(new ThreadStart(Function));
th.Start();
private static void Function()
{
//被线程调用的方法
}
二、调用有一个参数的函数
Thread th = new Thread(new ParameterizedThreadStart(Function));
th.Start("需要传递的参数");
private static void Function(object obj)
{
//被线程调用的方法
}
三、调用有多个参数的函数
MyClass m = new MyClass();
m.name = "佚玥";
m.age =24;
Thread th = new Thread(new ThreadStart(m.Function));
th.Start();
//自己定义的参数传递类
class MyClass
{
public string name;
public int age;
//自己需要的参数 都 设置 成 字段 或属性
public void Function()
{
//被线程调用的方法
}
}
相关文章推荐
- C#线程调用带参数的方法 ~
- C# 中跨线程的调用的方法--this.invoke
- C#线程调用带参数的方法 ~
- C#线程调用带参数的方法 ~
- C# 线程调用带参数的方法
- C#线程调用带参数的方法
- C# 子线程调用主线程窗体的解决方法
- C#中用Invoke调用控件方法和BeginInvoke线程使用方法
- c#带参数和返回值的函数 开启线程调用的方法
- C#构建多线程应用程序(1) —— 使用委托来自动创建次线程以实现异步方法的调用
- C#线程调用带参数的方法
- C# 跨线程调用TextBox方法浅析
- C# 子线程调用主线程窗体的解决方法
- [C#]线程调用带参数的方法 转
- C# 跨线程调用TextBox方法浅析
- C#线程调用带参数的方法
- C#定时调用方法 (线程)
- C# 子线程调用主线程窗体的解决方法
- c#中跨线程调用windows窗体控件 .我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题,下面我将详细的介绍。
- C#线程调用带参数的方法