In my WPF client, I have a loop that calls a WCF service to update some records. When the loop is done, I display a message, ‘Update complete’.
I’m changing my WCF calls to async calls now.
ServiceClient client = new ServiceClient(); client.UpdateRecordsCompleted +=new System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_UpdateRecordsCompleted); foreach (MyItem item in someCollection) { client.UpdateRecordsAsync(item); } MessageBox.Show('Update complete');
I don’t need to do anything in the competed event of each operation. I need to just display a message at the end of the last one.
Any ideas?
EDIT: I may be porting this to Silverlight, so that’s why I need to call the service asyncronously. I don’t think I can use the background worker.
I would add a thread-safe field to your WPF window to track the number of client updates the user has queued:
Before dispatching the individual async operations, set recordsQueued to someCollection.Count.
Finally, in client_UpdateRecordsCompleted, decrement recordsQueued; if it is zero, display the ‘Update Complete’ message: