C#线程的方法 [英] c# thread method

查看:79
本文介绍了C#线程的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个

public void Method(int m)
{
  ...
}

我怎样才能创建一个线程来这个方法?

how can I create a thread to this method?

主题T =新的Thread((法));

Thread t = new Thread((Method));

t.Start(M)

t.Start(m);

不工作。

推荐答案

在调用的方法需要一个参数。因为它有一个参数和一个返回void类型,你可以使用下面的

The method you are calling requires a parameter. Because it has one parameter and a return type of void you can use the following

ThreadPool.QueueUserWorkItem(o => Method(m));

您不必使用这种方法的int值更改为对象的方法签名。

You do not need to change the int to an object in the method signature using this method.

有使用过手动启动自己的线程线程池的优势。
主题VS线程池

There are advantages to using the ThreadPool over starting your own Thread manually. Thread vs ThreadPool

这篇关于C#线程的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆