private void PluginThread()
{
Hashtable nextrun = new Hashtable();
pluginthreadrun = true;
PluginThreadrunner.Reset();
while (pluginthreadrun)
{
try
{
lock (Plugin.PluginLoader.Plugins)
{
foreach (var plugin in Plugin.PluginLoader.Plugins)
{
if (!nextrun.ContainsKey(plugin))
nextrun[plugin] = DateTime.MinValue;
if (DateTime.Now > plugin.NextRun)
{
// get ms till next run
int msnext = (int) (1000/plugin.loopratehz);
// allow the plug to modify this, if needed
plugin.NextRun = DateTime.Now.AddMilliseconds(msnext);
try
{
bool ans = plugin.Loop();
}
catch (Exception ex)
{
log.Error(ex);
}
}
}
}
}
catch
{
}
// max rate is 100 hz - prevent massive cpu usage
System.Threading.Thread.Sleep(10);
}
while (Plugin.PluginLoader.Plugins.Count > 0)
{
var plugin = Plugin.PluginLoader.Plugins[0];
try
{
plugin.Exit();
}
catch (Exception ex)
{
log.Error(ex);
}
Plugin.PluginLoader.Plugins.Remove(plugin);
}
PluginThreadrunner.Set();
return;
}