I have a list of Contacts as follows.
List<string> Numbers = new List<string>();
This list can have any length of numbers in it. I want to send message to these numbers one by one and also report the progress to the user on a WinForm so I have a method like this.
private void ProcessBroadcast()
{
foreach (var number in Numbers)
{
//Send a Message here
messageWorker.RunWorkerAsync(message);
}
}
Since sending a message takes time so we opted to use BackgroundWorker to send a message. Now here the issue is we want to continue to send message to the next number in the foreach loop only when Background worker has completed.
I have implemented
messageWorker_DoWork
&
messageWorker_RunWorkerCompleted
and I am able to get the Number in messageWorker_RunWorkerCompleted method. I have done my research but couldn't find anything related to this.