Timer事件没有触发
在其他页面调用
StartUpdateDBTimer_Host();
为什么updateConfigTimer_Host_Tick(object sender, EventArgs e) 这个事件没有触发呢
哪位高手决绝一下
Timer _updateConfigTimer_Host;
private void StartUpdateDBTimer_Host()
{
_updateConfigTimer_Host = new Timer();
_updateConfigTimer_Host.Tick += new EventHandler(updateConfigTimer_Host_Tick);
//
// 每分钟更新一次
//
_updateConfigTimer_Host.Enabled = true;
_updateConfigTimer_Host.Interval = 1 * 10 * 1000;
_updateConfigTimer_Host.Start();
}
void updateConfigTimer_Host_Tick(object sender, EventArgs e)
{
Model.ISystemConfig _config =
new Logic.SystemConfigurationReader_FromDB().SetKey("主机").ReadConfig();
if (_config == null)
{
_config = new Model.SystemConfig();
_config.KeyName = "主机";
_config.OnOff = true;
_config.Value1 = RunTimeData.Instance.CommandPackage.GetStringValue(XManager.Dog.enuFunction.局域网点数).ToString();
_config.Value2 = DateTime.Now.ToString();
_config.Value3 = "";
_config.Value4 = "";
_config.Value5 = "";
_config.Memo = "";
}
else
{
_config.Value1 = DateTime.Now.ToString();
}
new Logic.SystemConfigurationWriter_ToDB().SetConfiguration("主机", _config).Flash();
}
--------------------编程问答-------------------- 快来高手帮帮忙呀 愁死我了 --------------------编程问答-------------------- public static void Main()
{
// Normally, the timer is declared at the class level, so
// that it doesn't go out of scope when the method ends.
// In this example, the timer is needed only while Main
// is executing. However, KeepAlive must be used at the
// end of Main, to prevent the JIT compiler from allowing
// aggressive garbage collection to occur before Main
// ends.
System.Timers.Timer aTimer = new System.Timers.Timer();
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
// Keep the timer alive until the end of Main.
GC.KeepAlive(aTimer);
}
// Specify what you want to happen when the Elapsed event is
// raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
} --------------------编程问答-------------------- 奇怪! --------------------编程问答-------------------- 问题已解决 因为调用这方法的方法是一个子线程
大家注意了
补充:.NET技术 , C#