private void btnBrowse_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); if (open.ShowDialog(this) == DialogResult.OK) { txtFileName.Text = open.FileName; treeDocLoadMethod(open.FileName); //this variable gives the name of selected file bgWorker.RunWorkerAsync(); } }//Browse button private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { xmlDocument = new XmlDocument(); Thread.Sleep(500); xmlDocument.Load(txtFileName.Text); btnBrowse.Enabled = false; } private void bgworker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // Set progress bar to 100% in case it's not already there. StripProgressBar.Value = 100; if (e.Error == null) { MessageBox.Show(xmlDocument.InnerXml, "Download Complete"); } else { MessageBox.Show("Failed to download file"); } // Enable the Browse button and reset the progress bar. this.btnBrowse.Enabled = true; StripProgressBar.Value = 0; toolStripStatusLabel1.Text = "work finished processing request."; }//workerCompleted