I am trying to figure out how to multi-thread an application. I am stuck trying to find the entry point to start the thread.
The thread that I am trying to start is : plugin.FireOnCommand(this, newArgs);
...
PluginBase plugin = Plugins.GetPlugin(Commands.GetInternalName(command));
plugin.FireOnCommand(this, newArgs);
...
The FireOnCommand method is:
public void FireOnCommand(BotShell bot, CommandArgs args)
I am not having any luck using ParameterizedThreadStart or ThreadStart, I can't seem to get the syntax correct.
EDIT: Tried both
Thread newThread =
new Thread(new ParameterizedThreadStart(plugin.FireOnCommand(this, newArgs)));
and
Thread newThread =
new Thread(new ThreadStart(plugin.FireOnCommand(this, newArgs)));
In .NET 2, you would need to create a method for this, with a custom type. For example, you could do:
internal class StartPlugin
{
private BotShell bot;
private CommandArgs args;
private PluginBase plugin;
public StartPlugin(PluginBase plugin, BotShell bot, CommandArgs args)
{
this.plugin = plugin;
this.bot = bot;
this.args = args;
}
public void Start()
{
plugin.FireOnCommand(bot, args);
}
}
You can then do:
StartPlugin starter = new StartPlugin(plugin, this, newArgs);
Thread thread = new Thread(new ThreadStart(starter.Start));
thread.Start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With