C# Backgroundworker Invoke for Progress Dialog

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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

View the full article
 
Back
Top