如何使用就地功能启动线程? [英] how to start a thread with in-place function?

查看:79
本文介绍了如何使用就地功能启动线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我可以启动一个线程并就地编写函数。所以,你用
可以用伪代码:


def someFunc:

thread.new(def summit:doSomeStuff() )


我怎样才能在C#中做到这一点?

In Java I can start a thread and write the function in-place. So, you
could do, in pseudocode:

def someFunc:
thread.new( def summit: doSomeStuff() )

How can I do that in C#?

推荐答案

你指的是匿名方法?


它们不存在于1.1中它们在2.0中。


parsifal < SE ************* @ gmail.com>在消息中写道

news:11 ********************* @ g44g2000cwa.googlegro ups.com ...
Are you refering to anonymous methods?

They are not present in 1.1 they are in 2.0 though.

"parsifal" <se*************@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
在Java中我可以启动一个线程并就地编写函数。所以,你可以用伪代码来做:

def someFunc:
thread.new(def summit:doSomeStuff())

我怎么能在C#中执行此操作?
In Java I can start a thread and write the function in-place. So, you
could do, in pseudocode:

def someFunc:
thread.new( def summit: doSomeStuff() )

How can I do that in C#?



您需要将ThreadStart委托的实例传递给您的线程类的

构造函数,像这样:


线程t =新线程(新的ThreadStart(doSomeStuff));


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" parsifal" < SE ************* @ gmail.com>在消息中写道

news:11 ********************* @ g44g2000cwa.googlegro ups.com ...
You need to pass an instance of the ThreadStart delegate to the
constructor for your thread class, like so:

Thread t = new Thread(new ThreadStart(doSomeStuff));

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"parsifal" <se*************@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
在Java中我可以启动一个线程并就地编写函数。所以,你可以用伪代码来做:

def someFunc:
thread.new(def summit:doSomeStuff())

我怎么能在C#中执行此操作?
In Java I can start a thread and write the function in-place. So, you
could do, in pseudocode:

def someFunc:
thread.new( def summit: doSomeStuff() )

How can I do that in C#?



如果使用2.0,您可以编写ThreadStart方法,因为Ignacio

指向。这是一个例子。


public static void Main()

{

ThreadStart doSomeStuff = delegate()

{

//把你的线程代码放在这里。

};


线程线程=新线程(doSomeStuff) );

thread.Start();

thread.Join();

}


Brian


parsifal写道:
If using 2.0 you can write the ThreadStart method in place as Ignacio
pointed. Here is an example.

public static void Main()
{
ThreadStart doSomeStuff = delegate()
{
// Put your thread code here.
};

Thread thread = new Thread(doSomeStuff);
thread.Start();
thread.Join();
}

Brian

parsifal wrote:
在Java中我可以启动一个线程并就地编写函数。所以,你可以用伪代码来做:

def someFunc:
thread.new(def summit:doSomeStuff())

我怎么能在C#中做到这一点?
In Java I can start a thread and write the function in-place. So, you
could do, in pseudocode:

def someFunc:
thread.new( def summit: doSomeStuff() )

How can I do that in C#?






这篇关于如何使用就地功能启动线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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