We help IT Professionals succeed at work.
Get Started

Clearing Cache System.Windows.Forms.WebBrowser

Envision11
Envision11 asked
on
2,789 Views
Last Modified: 2013-11-07
I am currently creating a System.Windows.Forms.WebBrowser() to render a page then convert that page to a Bitmap to used in a PDF.
This all works with out issue, but the WebBrowser() keeps caching the same stylesheet which can be selected by the user.
So i am looking for a way to completely clear the cache of this browser each time its called.( Clearing FF / IE has not affect )

			private void CreateHtml2BitmapThread(object _Params)
			{
				System.Windows.Forms.WebBrowser Browser = null;

				ConvertHtmlToBitmapParams Params = (_Params as ConvertHtmlToBitmapParams);

				try
				{
					Browser = new System.Windows.Forms.WebBrowser();
					Browser.Refresh(System.Windows.Forms.WebBrowserRefreshOption.Completely);
					Browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(IsDocumentCompleted);
					Browser.Size = new Size(DOCUMENT_WIDTH,DOCUMENT_HEIGHT);
					Browser.ScrollBarsEnabled = false;
					
					Browser.Navigate(new Uri(Params.m_sURL));

					int Timeout = 100;
					while ((!bIsDocumentCompleted) || (Timeout <= 0))
					{
						System.Windows.Forms.Application.DoEvents();
						Thread.Sleep(100);
						Timeout--;
					}

					if (bIsDocumentCompleted)
					{
						Bitmap TempBitmap = new Bitmap(BITMAP_WIDTH,BITMAP_HEIGHT);
						Browser.DrawToBitmap(TempBitmap,new Rectangle(0,0,BITMAP_WIDTH,BITMAP_HEIGHT));
						Params.m_BitmapList.Add(TempBitmap);
					}
				}
				catch (Exception _Ex)
				{
					DebugUtils.LogException(_Ex);
				}

				if (Browser != null)
				{
					Browser.Dispose();
				}

				Params.m_bHaveGotData = true;
			}

			private void IsDocumentCompleted(object sender,System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
			{
				bIsDocumentCompleted = true;
			}

Open in new window

Comment
Watch Question
CEO @ Arkro IT
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE