我在C#中遇到了多线程问题。我通过foreach字典对象开始线程。
问题是插件对象在ParameterizedThread启动之前被下一个字典对象覆盖。
我如何不使用Thread.Sleep(10)之类的东西或等待ThreadState更改为“正在运行”而解决此问题?
_pluginWorkers = new Dictionary<string, Action<DateTime, DateTime>>();
... Filling _pluginWorkers with objects ...
foreach (var plugin in _pluginWorkers)
{
var pluginAction = new ParameterizedThreadStart(obj => plugin.Value(timestart, timeend));
Thread actionThread = new Thread(pluginAction, 1024 * 1024);
actionThread.Start();
}