Async actions inside Silverlight Method - returning the value

Posted by tyndall on Stack Overflow See other posts from Stack Overflow or by tyndall
Published on 2010-03-26T04:03:01Z Indexed on 2010/03/26 4:13 UTC
Read the original article Hit count: 441

Filed under:
|
|
|
|

What is the proper way to call an Async framework component - wait for an answer and then return the value. AKA contain the entire request/response in a single method.

Example code:

    public class Experiment
    {
     public Experiment()
     {

     }
        public string GetSomeString()
        {
            WebClient wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
            Uri u = new Uri("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&topic=t&output=rss");
            wc.DownloadStringAsync(u);
            return "the news RSS from Google";
        }

        private void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {

            //don't really see how this callback method makes it able
            // to return the answer I'm looking for on the return
            // statement in the method above.
        }
    }

MORE INFO: The reason I'm asking this that I have a project I'm working on where I'd like JavaScript code in the browser to use Silverlight like a Facade/Proxy to Web services and complex calculations & operations. I'd like to make the calls to the [ScriptableMembers] in Silvelight synchronously. I don't want Silverlight to callback into the browser's JavaScript

© Stack Overflow or respective owner

Related posts about asynchronous

Related posts about Silverlight