title: Hooked Events for internet explorer is not working some times
body: <p>I am trying to register the events from internet explorer. Following is the code and its working fine.</p>
  
  <pre><code>public void Start()
          {
              shellWindows.WindowRegistered -= new SHDocVw.DShellWindowsEvents_WindowRegisteredEventHandler(shellWindows_WindowRegistered);
              shellWindows.WindowRegistered += new SHDocVw.DShellWindowsEvents_WindowRegisteredEventHandler(shellWindows_WindowRegistered);
              shellWindows.WindowRevoked -= new SHDocVw.DShellWindowsEvents_WindowRevokedEventHandler(shellWindows_WindowRevoked);
              shellWindows.WindowRevoked += new SHDocVw.DShellWindowsEvents_WindowRevokedEventHandler(shellWindows_WindowRevoked);
  
              "Listening to web events".AppendToTextFile(logFilePath);
              StartListening();
          }
  </code></pre>
  
  <p>The StartListening() function shown above binds the document events for the internet explorer tab. The binding function is also defining below.</p>
  
  <pre><code> private void BindDocumentEvents(InternetExplorer ie)
          {
              try
              {
                  HTMLDocument doc = (HTMLDocument)ie.Document;
                  HTMLDocumentEvents2_Event docEvents = doc as HTMLDocumentEvents2_Event;
                  docEvents.onclick += new HTMLDocumentEvents2_onclickEventHandler(htmlDoc_Click);
                  docEvents.onkeyup += new HTMLDocumentEvents2_onkeyupEventHandler(htmlDoc_KeyUp);
                  //docEvents.onkeypress += new HTMLDocumentEvents2_onkeypressEventHandler(htmlDoc_KeyPress);
                  docEvents.onselectionchange += new HTMLDocumentEvents2_onselectionchangeEventHandler(htmlDoc_Selectionchange);
              }
              catch (System.Runtime.InteropServices.COMException e)
              {
                  Console.WriteLine("Exception: {0}", e.Message);
                  Console.WriteLine("Exception code: {0}", e.ErrorCode);
                  Console.WriteLine("Exception description: {0}", e.InnerException.Message);
              }
  
          }
  </code></pre>
  
  <p>The bind events and its binding functions shown above like 'htmlDoc_Click' is working only for sometimes and the binding breaks.</p>