我试图弄清楚如何对应用程序进行多线程处理。我一直在努力寻找启动线程的入口点。

我正在尝试启动的线程是:plugin.FireOnCommand(this,newArgs);

...
PluginBase plugin = Plugins.GetPlugin(Commands.GetInternalName(command));
plugin.FireOnCommand(this, newArgs);
...

FireOnCommand方法是:
 public void FireOnCommand(BotShell bot, CommandArgs args)

使用ParameterizedThreadStart或ThreadStart我没有任何运气,我似乎无法正确使用语法。

编辑:都尝试了
Thread newThread =
  new Thread(new ParameterizedThreadStart(plugin.FireOnCommand(this, newArgs)));


Thread newThread =
  new Thread(new ThreadStart(plugin.FireOnCommand(this, newArgs)));

最佳答案

这是一些示例代码:

class BotArgs
{
    public BotShell Bot;
    public CommandArgs Args;
}

public void FireOnCommand(BotShell bot, CommandArgs args)
{
    var botArgs = new BotArgs {
        Bot = bot,
        Args = args
    };
    var thread = new Thread (handleCommand);
    thread.Start (botArgs);
}

void handleCommand (BotArgs botArgs)
{
    var botShell = botArgs.Bot;
    var commandArgs = botArgs.Args;
    //Here goes all the work
}

09-16 03:51