Cracker
Cracker

Reputation: 912

Timer doesn't start


I've simply added a timer (System.Windows.Forms.Timer) to form in my app. When i call Timer1.Start(); from an EventHandler of IE's object's (SHDocVw.InternetExplorer) DocumentCompleted event like this:

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

It doesn't throw any kind of exception, simply doesn't start. If I call the method from any other functions, the timer starts.
How can I fix this?
Thanks in advance.

Upvotes: 0

Views: 931

Answers (1)

Tim Coker
Tim Coker

Reputation: 6524

Try doing the call like this. As others have mentioned, you're probably calling from a different thread than who owns the timer.

    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();
    }

Upvotes: 3

Related Questions