WebBrowser的內存釋放


WebBrowser窗口自動滾動:

this.webBrowser.Document.Window.ScrollTo(0, webBrowser1.Document.Body.ScrollRectangle.Height);
 
WebBrowser的腳本出錯信息:
當頁面上的腳本出錯時,一般情況下會彈出腳本出錯提示,如果在用WB寫爬蟲一類的時候,這類提示可能會導致系統不能工作,解決的發是:
(1)設置屬性ScriptErrorsSurpressed = true;
(2)打開IE的設置 "Internet選項" - "高級" - 勾選"禁用腳本調試"
 
WebBrowser的內存釋放:
WB的內存開銷很大,當連續打開很多網頁時這個問題將會非常明顯,甚至耗盡內存,解決的方我在MSDN論壇上找到(來源: http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8/),具體如下:
 
 
This solution worked for me!! 
Thank you so much mike_t2e!!!!!!!

-----------------------------------------------------------------------

Is the memory released when you minimize the app ? If so, try this:


-- in class definition 

        [DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
        internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);

        [DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
        internal static extern IntPtr GetCurrentProcess();

-- code to call when you want to reduce the memory

            IntPtr pHandle = GetCurrentProcess();
            SetProcessWorkingSetSize(pHandle, -1, -1);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM