我有一个带有定时器控件的dll,里面有一个消息框。计时器已启用且间隔已设置为100秒,但由于某种原因它没有触发。我添加了按钮以检查它是否已启用,并且timer1.enabled属性设置为true,但它甚至不会触发一次。什么想法可能是错的?谢谢!
Dll代码:
private void timer1_Tick(object sender, EventArgs e)
{
MessageBox.Show("Test");
}
这就是我调用dll表单的方式:
M.ModuleInterface module = Activator.CreateInstance(t) as M.ModuleInterface;
Thread t = new Thread(module.showForm);
t.Start();
showForm方法:
void M.ModuleInterface.showForm()
{
log("GUI::Initialized()");
frm.ShowDialog();
}
答案 0 :(得分:1)
我相信,仅凭你的话来判断,你只是忘了注册时间。
做的:
public Form1()
{
InitializeComponent();
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
}
private void timer1_Tick(object sender, EventArgs e)
{
// Your code here
}
这个小例子很好用:
private System.Windows.Forms.Timer timer1;
public Form1()
{
InitializeComponent();
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 100;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
timer1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
// timer is triggered. code here is called
}