[SOLVED] Download button does not display

Issue

I have a weird problem..

I am working on creating a thumbnail of a webpage! I have never worked with threading and I have a issue

I am using the following code

protected void GetScreenshot_Click(object sender, EventArgs e)
{
  path = Server.MapPath(FolderID);
  Thread webBrowseThread = new Thread(new ThreadStart(PerformWebBrowseOp));
  webBrowseThread.SetApartmentState(ApartmentState.STA);
  webBrowseThread.Start();
}          

protected void PerformWebBrowseOp()
{
  if(searchedword!='')
  {
    Directory.CreateDirectory(path);
  }

  string path1 = Mypath + "/image.png";
  GeneateScreenshot gn = new GeneateScreenshot();
  Bitmap thumbnail = gn.GenerateScreenshot("http://www.google.com/search?hl=en&q=" + Searchedword, 1024, 768);
  FileStream imageStream = new FileStream(path1, FileMode.Create);
  thumbnail.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
  imageStream.Close();
  downloadbutton.Visible=true;
}

now my problem is i have a download button to be displayed when the thumbnail has been created.. but for some reason the donwload button is not getting generated or is not visible!

I tried placing in the getscreenshot_click but it gets created even before the the thread has started running and before the thumbnail has been created.

Can someone help me fix this issue?

Solution

The simplest way to solve this problem was to use webBrowseThread.join() to wait till the process is done and then say downloadbutton.visible= true !

Answered By – helpme

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *