I am developing wpf application using MVVM Prism. I got four views , MainWindow, ViewB, ViewC and ViewD and all are attached with their respective ViewModel. I initialized the backgroundworker at application start. see the following background worker class.
public class BackGroundThread
{
public BackgroundWorker bgWrk;
public bool stopStatus;
public int GetPercent;
public BackGroundThread()
{
bgWrk = new BackgroundWorker();
bgWrk.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
bgWrk.ProgressChanged += backgroundWorker_ProgressChanged;
bgWrk.DoWork += bw_DoWork;
bgWrk.WorkerReportsProgress = true;
}
public void backgroundWorker_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e) {
}
public void backgroundWorker_ProgressChanged(object sender,ProgressChangedEventArgs e)
{
Overall.EverythingOk = e.ProgressPercentage.ToString();
}
public void bw_DoWork(object sender, DoWorkEventArgs e)
{
int i = 1;
while (!stopStatus)
{
GetPercent = I;
if (i == int.MaxValue)
i = 0;
i = i + 1;
}
}
}
I called it from MainWindow.xaml.cs and start background worker.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ViewModel.MainWindowsViewModel viewModel = new ViewModel.MainWindowsViewModel();
this.DataContext = viewModel;
BackGroundThread bgT = new BackGroundThread();
bgT.bgWrk.RunWorkerAsync();
}
}
How can i call the GetPercent variable from the rest of the view? For example, when i navigate to ViewC, ViewC show the real time value using Label or TextBlock (Value is keep increasing.). Then i go to ViewB, ViewB also show real time increment of GetPercent variable.
Any help, really appreciate it.
Thanks