Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

C# Backgroundworker Invoke for Progress Dialog

$
0
0

Hi,

   I have the following code & wish to call the 'OpenASite' method using the background worker while a progress dialog is displayed (form2 just has a 'Please wait...' message). The 'OpenASite' method uses a treeView control on the main form so I am aware I need to use a delegate in the DoWork handler to avoid cross threading problems. Can anyone help with finishing the required code?

Thanks

Paul.

namespace ProgressTest
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        BackgroundWorker worker;
        Form2 frm; //Progress Dialog

        private void OpenSite_Click(object sender, EventArgs e)
        {

            frm = new Form2();
            worker = new BackgroundWorker();
            worker.WorkerReportsProgress = true;
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
            worker.RunWorkerAsync();
            frm.ShowDialog();

        }

        void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {

            
        }       
       
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
           
            frm.Close();
            
        }       
       
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
           
            //OpenASite Here using Invoke?

        }

        private void OpenASite()
        {

            //Show progress dialog here (form2)

            //Load locations into tree view
            LoadTreeViewLocations();

            //Load systems into tree view
            LoadTreeViewSystems();

            //Expand Treeview
            treeViewAssets.ExpandAll();

            //Close progress dialog (form2)
        }
    }
}


Paul Wainwright


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>