XML inside WebBrowser control causes large delay when unloading the control
-
Has anyone experienced this, or a workaround? I am using a WebBrowser control to display an xml file from the file system. The size of the xml file is 190k. Everything is fine except when I close the control (say using a tabbed interface). When closing/removing the browser control, the application experiences a large delay (~7 secs on my machine). Internet Explorer (7) does not show this behavior; it loads up the file at the same speed (as me) and closes immediately with no delay. Any insight would be appreciated. Here is the code I refined down to illustrate the problem.
private void Form1_Load(object sender, EventArgs e) { TabPage page = this.tabControl1.TabPages[0]; WebBrowser wb = (WebBrowser)page.Controls[0]; // this file is ~190k, takes 3 secs to load. wb.Navigate(@"D:\temp\large.xml"); } private void button1_Click(object sender, EventArgs e) { // From here... this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab); // ... to here takes about 7 seconds. }
Michael Developer, Author, Chef
-
Has anyone experienced this, or a workaround? I am using a WebBrowser control to display an xml file from the file system. The size of the xml file is 190k. Everything is fine except when I close the control (say using a tabbed interface). When closing/removing the browser control, the application experiences a large delay (~7 secs on my machine). Internet Explorer (7) does not show this behavior; it loads up the file at the same speed (as me) and closes immediately with no delay. Any insight would be appreciated. Here is the code I refined down to illustrate the problem.
private void Form1_Load(object sender, EventArgs e) { TabPage page = this.tabControl1.TabPages[0]; WebBrowser wb = (WebBrowser)page.Controls[0]; // this file is ~190k, takes 3 secs to load. wb.Navigate(@"D:\temp\large.xml"); } private void button1_Click(object sender, EventArgs e) { // From here... this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab); // ... to here takes about 7 seconds. }
Michael Developer, Author, Chef
Well, it seems whenever i ask a question I figure out a workaround. In this case, I am still not 100% sure why this works. And yes, the DoEvents() is necessary for this the page to close quickly (due to asnync loading I guess).
private void button1_Click(object sender, EventArgs e) { // From here... WebBrowser wb = (WebBrowser)this.tabControl1.SelectedTab.Controls[0]; wb.Navigate(""); Application.DoEvents(); this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab); // ... to here now takes about 1 second. }
Michael Developer, Author, Chef