计时器无法启动

时间:2011-05-06 12:58:59

标签: c# timer


我只是在我的应用中添加了一个计时器(System.Windows.Forms.Timer)。当我从IE的对象(Timer1.Start();SHDocVw.InternetExplorer事件的EventHandler中调用DocumentCompleted时,这样:

    private void internetExplorer_DocumentComplete(object sender, ref object args)
    {
        timer1.Start();
    }

它不会抛出任何异常,只是不启动。如果我从任何其他功能调用该方法,则计时器启动 我该如何解决这个问题? 提前谢谢。

1 个答案:

答案 0 :(得分:3)

尝试像这样打电话。正如其他人所提到的那样,你可能会使用与拥有计时器的人不同的线程来打电话。

    private void internetExplorer_DocumentComplete(object sender, ref object args)
    {
        if (this.InvokeRequired)
        {
            Action<object, object> del = internetExplorer_DocumentComplete;
            this.Invoke(del, sender, args);
            return;
        }
        timer1.Start();
    }