-1

Currently I have a picture box holding up two items on it one processing gif file and a label. Now I have called the BringToFront() for all three items (picture box,processing gif, label) when ever backgroundworker is being invoked

Below is my code snippet for back ground worker

private void buttonUpload_Click(object sender, EventArgs e) { LoadFile(pdfFullPath); bgwLoadFile.RunWorkerAsync(dummyPDFPath); pictureBox1.BringToFront(); picLoading.BringToFront(); label.BringToFront(); } private void bgwLoadFile_DoWork(object sender, DoWorkEventArgs e) { this.Invoke((MethodInvoker)delegate() { acrPDFViewer.LoadFile(e.Argument.ToString()); }); } private void bgwLoadFile_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled == true) { } else if (e.Error != null) { } else { pictureBox1.SendToBack(); picLoading.SendToBack(); label.SendToBack(); } } 

While executing it fails to show me up none of the three items.

4
  • Are you getting some Exception or error message? Commented Apr 15, 2013 at 12:29
  • Im not getting any exceptions or errors .. when i debug it , it goes though all steps but no action has been taken place Commented Apr 15, 2013 at 12:30
  • Are you sure that you are reaching the bgwLoadFile_RunWorkerCompleted event handler? You might need to repeatedly call Application.DoEvents() to ensure that the RunWorkerCompleted event is properly fired. Commented Apr 15, 2013 at 12:38
  • This is the third time you asked the same question: stackoverflow.com/questions/15152850/… and stackoverflow.com/questions/15703045/… if you need further guidance please include more details in your questions. Commented Apr 15, 2013 at 12:43

1 Answer 1

3

This works for me:

public partial class Form1 : Form { public Form1() { InitializeComponent(); UpdateControls(false); bgwLoadFile.DoWork += new DoWorkEventHandler(bgwLoadFile_DoWork); bgwLoadFile.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgwLoadFile_RunWorkerCompleted); } private void buttonUpload_Click(object sender, EventArgs e) { UpdateControls(true); bgwLoadFile.RunWorkerAsync(); } void bgwLoadFile_DoWork(object sender, DoWorkEventArgs e) { //simulate work System.Threading.Thread.Sleep(2000); } void bgwLoadFile_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if(!e.Cancelled && e.Error == null) UpdateControls(false); } private void UpdateControls(bool isVisable) { if (isVisable) { pictureBox1.BringToFront(); picLoading.BringToFront(); label1.BringToFront(); } else { pictureBox1.SendToBack(); picLoading.SendToBack(); label1.SendToBack(); } } } 

If all you want to do is to make these three controls show only while the backgroundworker is active you could change the UpdateControls()-method to this:

private void UpdateControls(bool isVisable) { pictureBox1.Visible = isVisable; picLoading.Visible = isVisable; label1.Visible = isVisable; } 
Sign up to request clarification or add additional context in comments.

3 Comments

Check that the code is executed by adding a breakpoint inside else before running the code.
yeah its executing but initailly it fails to shown up the picturebox , label ,loading image despite of provding BringToFront()
@Ganeshja Updated my answer, take a look.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.