Updated This is kind of an interesting problem I am experiencing. I need to have a progress dialog show when a background process is running. Normally, this would work but the problem is that I need to set public static data within the background process. Here is an example of what I am attempting to accomplish:
public partial class MainWindow : Window { public static Service binding; public static Result lr; public progressDialog dlg; private void login() { string sPwd = txtPwd.Password; string sEmail = txtEmail.Text; binding = new Service(); lr = binding.login(sEmail, sPwd); } private void btnLogin_Click(object sender, RoutedEventArgs e) { BackgroundWorker worker = new BackgroundWorker; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted) worker.RunWorkerAsync(); dlg = new progressDialog(); dlg.Show(); login(); } private void worker_DoWork(object sender, DoWorkEventArgs e) { e.Result = login(); } private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { this.Hid(); Window1 newWindow = new Window1(); newWindow.Show(); dlg.Close(); }
I know that as this stands, it will not work because login() is a void and does not actually return a value to use with e.Result in the DoWork event. However, I have set up a login class to pass the parameters to and I still receive errors stating that I cannot access the UI thread. The main problem is that lr and binding are accessed by another window so they must be public static data (from the other window I set public static Service binding = MainWindow.binding;). I'm just having a bit of trouble wrapping my head around how exactly to set this up.