Silverlight WCF with Multiple Calls need to know when all are completed
I am working on a Small silverlight application to resize images on the client machine before uploading to the server via a WCF service. I have all this working, the client connects and uploads the images are resizing, but the nature of the application is that the user is shown some form of progress indicator as the images upload and they cant upload any more, this is working sort of.
I thought i would wire up the Completed event of the call to the service:
service.SaveImageCompleted += new EventHandler<AsyncCompletedEventArgs>(service_SaveImageCompleted);
the way i thought i could simply get this to work would be to get a count of all the calls i need to make (the count of the number of images seleted to process) and then just do a check inside the Completed event handler:
void service_SaveImageCompleted(object sender, AsyncCompletedEventArgs e)
{
serviceCallsMade++;
if (totalServiceCalls == serviceCallsMade)
{
// MessageBox.Show("Transactions Complete!");
IsWorking = false;
ProgressBarWorking.Visibility = Visibility.Collapsed;
UploadButton.Visibility = Visibility.Visible;
开发者_开发知识库 LayoutMessage.Visibility = Visibility.Visible;
}
}
The issue i am having is that what i thought was the final call (the UI getting "unblocked") happens way before all the service calls are actually completed (i am looking at this via fiddler). Locally this worked, but i now think it was becuase it was processed quickly and i didnt notice, on the pre production environment you can see that my implementation is tosh :).
Does anyone out there no what the best approach to this is, this is not a massive part of the overall system, and doesnt need to be overly fancy but i would like to give the correct feedback, and this way of programming (Async stuff) needs more time to get into my head.
Any help would be much appreciated.
Rob
That should work as long as the processing on the server side is done on a single thread. If you do happen to spin up another thread then the completed event will potentially get done before the actual work is done.
精彩评论