2014-10-02 42 views
1

我正在使用WebBrowser control停止如果webBrowser控件掛起的過程

這個工作正常,但大多數情況下,但是導航到新頁面或等待新頁面加載有時可能會掛起。

有沒有辦法解決這個問題?即如果頁面在一段時間後未能導航或加載,那麼殺死該進程?

我正在使用 - webBrowser1_DocumentCompleted事件來獲取頁面加載/導航時的某些行爲,但不知道如何捕捉頁面是否掛起?

+0

如果它仍然處於忙碌狀態,您可以在某個時間後檢查IsBusy屬性,然後通過在Web瀏覽器控件上調用Stop方法強制停止加載 – Thangadurai 2014-10-02 10:34:31

回答

1

Maby你應該嘗試實現某種超時邏輯?網上有很多關於這個的樣本。 F.E. this one

而且您可能會感興趣的WebBrowserControl ProgressChanged

0

此事件這是由於WebBrowser組件是Internet Explorer中的非常基本的模型,它會卡在AJAX頁面。您可以明確解決此問題以使用最新版本的Internet Explorer ...使用此代碼...

 try 
     { 
      string installkey = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; 
      string entryLabel = "YourExe.exe"; 
      string develop = "YourExe.vshost.exe";//This is for Visual Studio Debugging... 
      System.OperatingSystem osInfo = System.Environment.OSVersion; 

      string version = osInfo.Version.Major.ToString() + '.' + osInfo.Version.Minor.ToString(); 
      uint editFlag = (uint)((version == "6.2") ? 0x2710 : 0x2328); // 6.2 = Windows 8 and therefore IE10 

      Microsoft.Win32.RegistryKey existingSubKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(installkey, false); // readonly key 

      if (existingSubKey.GetValue(entryLabel) == null) 
      { 
       existingSubKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(installkey, true); // writable key 
       existingSubKey.SetValue(entryLabel, unchecked((int)editFlag), Microsoft.Win32.RegistryValueKind.DWord); 
      } 
      if (existingSubKey.GetValue(develop) == null) 
      { 
       existingSubKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(installkey, true); // writable key 
       existingSubKey.SetValue(develop, unchecked((int)editFlag), Microsoft.Win32.RegistryValueKind.DWord); 
      } 
     } 
     catch 
     { 
      MessageBox.Show("You Don't Have Admin Previlege to Overwrite System Settings"); 
     } 
    } 

右鍵單擊您的Exe。和vshost.exe並以管理員身份運行以更新此應用程序的註冊表....