eric.itzhak
eric.itzhak

Reputation: 16062

changing visibility not working

I have a Label and PictureBox element that in designer i set visibility as false.

now i try this :

   private void openExcelButton_Click(object sender, EventArgs e)
    {

        openExcelDialog.Filter = "Excel files|*.xls;*.xlsx;*.csv";
        DialogResult result = openExcelDialog.ShowDialog();
        if (result == DialogResult.OK) // Test result.
        {
            LoadingGIF.Visible = true;
            LoadingLabel.Text = "Loading...";
            LoadingLabel.Visible = true;
            string file = openExcelDialog.FileName;

            //more code
            LoadingGIF.Visible = false;
            LoadingLabel.Text = "Uploading Finished!";



        }
    }

Now when pressing the button and choosing a file nothing happens untill i finish the code in the //more code section and then the label changes.

Why does this happen?

Upvotes: 0

Views: 561

Answers (1)

Jammin411
Jammin411

Reputation: 418

The reason this happens is because your main thread is becoming non-responsive and not allowing the changes to happen in a sequential order. I had a very similar issue on a project a year ago. The suggested solution by MS is to use a background worker to open the file and manipulate it so the primary thread does not become non-responsive. Microsoft has a fairly decent example of how to use a background worker here: http://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx

Upvotes: 1

Related Questions