c#在循环中创建多个带有代码中事件的计时器(表单组件)



基本上-如何实现这一点。代码是千言万语吗?它的设计有缺陷吗?

TimersConfig timersConfig = ConfigurationManager.GetSection("Timers") as TimersConfig;
            foreach (TimerElement t in timersConfig.Timers)
            {
                System.Windows.Forms.Timer timerComponent = new System.Windows.Forms.Timer();
                timerComponent.Interval = t.Interval;
                timerComponent.Tick += new EventHandler(timerComponent_Tick);
            }

如果你所说的"让它工作"是指计时器不工作,那是因为你还没有启动它们
将其添加到循环的末尾:

timerComponent.Start();

最新更新