views:

142

answers:

1

Hello,

I am developing a silverlight application, where I make use of webservices. The server is responsible for processing some text, get the phoneme info, convert to visemes, generate the audio and encode to mp3. A list of visemes and a path to the create audio file is returned. Then the audio is streamed to the client.

But now, I have a problem. I need for the server to wait for complete audio encoding creation. Sometimes, the audio is not ready, and it does not stream for the client. I 've tried thread.join but it has the same problem for long texts.

How should be the best way to resolve this issue ?

Thanks in advance

+1  A: 

Hi there,

maybe I misunderstood your question, but I think this should not present a big problem as the async pattern should actually help you... My intuitive understanding of this scenario would be something like this:

myWebServiceClient.ProcessTextCompleted += (sndr, evnt) =>
{
  IsBusy = false;
  var url = evnt.Result.PathToCreatedAudioFile;
  PlayAudioFile(url);
};
IsBusy = true;
myWebServiceClient.ProcessTextAsync("abcdefg");

Maybe you could give a bit more information on why this is not working for your case.

Cheers, Alex

alexander.biskop
I think the problem is because the service is async so it does not wait for all operations to complete, it just sends all the information. but since the encoding function can take longer, the webservice gets the info required (stream address, etc) but the file isn't ready yet. I need to wait for encoding process. Thanks for the help! : )
wasd_sederap_wasd
Well, only the server knows when exactly the processing has finished, so I think it should not return anything before it has actually finished processing the request and the file is ready. So maybe the problem lies in your server-side implementation, not the client-side.
alexander.biskop
Yes, that's why i've created a thread to encode, and then thread.join method. but it doesn't work. :(
wasd_sederap_wasd
Hi, okay now I got it. So the question in essence is: How can I wait for a worker thread to complete its work? That right?This is not a trivial task, so you'll have to go through a couple of tutorials/docs I guess, but what you are looking for is the AutoResetEvent class (http://msdn.microsoft.com/de-de/library/system.threading.autoresetevent.aspx) or maybe the ManualResetEvent. These classes will allow you to wait for a thread to finish.Implementing your scenario that way would be the cleanest solution possible I think.
alexander.biskop
Still I don't understand why Join() method doesn't work... By the description it is exactly what I'm looking for.. :(
wasd_sederap_wasd