Search code examples
silverlightwebclientashx

How can I know on the client side when the HTTP handler is done processing?


Probably a long question for a simple solution, but here goes...

I have a custom made silverlight control for selecting multiple files and sending them to the server. It sends files to a general handler (FileReciever.ashx) using the OpenWriteAsync method of a WebCLient control.

Basically, the silverlight code does something like this for each file:

WebClient client = new WebClient();
client.OpenWriteCompleted += (sender, e) =>
  {
    PushData(data, e.Result);
    e.Result.Close();
    data.Close();
  };
client.OpenWriteAsync(handlerUri); 

The server side handler simply reads the incoming stream, and then does some more processing with the resulting byte array.

THE PROBLEM is that client side OpenWriteCompleted is done as soon as all the data has been sent over the wire. My code will then contine with the next file. What I really want is to wait until the ASHX handler has finished with all it's processing of that request. How do I do that? Any wait mechanism on WebClient? Any callback I can do on the HttpContext in the handler? Should I use some other kind of transfer technique? Please advice!


Solution

  • Hrm, maybe a simple solutioin could be to tag the url with a GUID(the guid being unique per file, or transfer, whatever makes sense to your situatuation). Then you can have another simple web service that is capable of checking on the status of the other service, based on the guid, and have your silverlight client query that new service for its processing status(by passing the new web service the guid of the past transfer).