I am using VS 2015 winform background workers to do some tasks.
I have DoWork()
method that uses List<string> myList
, and it removes each entry in the list once certain process is complete. My goal is to let users know which entry in myList
was not processed (since it deletes an entry after every process, whatever is left in the end is the one that is NOT processed). To do so, I was going to pass the myList
variable to RunWorkerCompleted()
, but not only do I not know how to do this, I am not even sure if this is the best way of doing it.
Are there better ways to let users know which entry in myList
was not processed, and if not, how would I pass a variable from DoWork() to RunWorkerCompleted()?
Current RunWorkerCompleted() method:
private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if(e.Error != null)
{
MessageBox.Show(e.Error.ToString());
}
else
{
MessageBox.Show("Done!");
}
}
Basically, I want the MessageBox to display which entries are not processed when it's done running a task
You can use the result of the RunWorkerCompletedEventArgs
See this
OK for some people who just don't want to read, use this
private void bgw_DoWork(object sender, DoWorkEventArgs e)
{
//Do your work
e.Result = mylist;
}
private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if(e.Error != null)
{
MessageBox.Show(e.Error.ToString());
}
else
{
ShowResult(e.Result as List<string>);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With