本文介绍了如何创建一个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的方法是我想在那个线程做什么:

The method below is what I want to be done in that thread:

public void Startup(int port,string path)
{
    Run(path);
    CRCCheck2();
    CRCCheck1();
    InitializeCodeCave((ushort)port);
}



我想我能找到谷歌上搜索,但毫无效果。

I tried what I could find googling,but nothing worked

public void Test(int port,string path)
{
    Thread t = new Thread(Startup(port,path));
}

public void TestA(int port,string path)
{
    Thread t = new Thread(Startup);
    t.Start (port,path);
}



两者都不编译,该怎么做?

Both don't compile,how to do that?

推荐答案

下面的工作方式。

// The old way of using ParameterizedThreadStart. This requires a
// method which takes ONE object as the parameter so you need to
// encapsulate the parameters inside one object.
Thread t = new Thread(new ParameterizedThreadStart(StartupA));
t.Start(new MyThreadParams(path, port));

// You can also use an anonymous delegate to do this.
Thread t2 = new Thread(delegate()
{
    StartupB(port, path);
});
t2.Start();

// Or lambda expressions if you are using C# 3.0
Thread t3 = new Thread(() => StartupB(port, path));
t3.Start();



启动方法有以下这些例子签名。

The Startup methods have following signature for these examples.

public void StartupA(object parameters);

public void StartupB(int port, string path);

这篇关于如何创建一个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 06:40