Silverlight waiting for asynchronous call

I have a silverlight application that went it starts up, it needs to read a config file that a webservice returns.

So, in my main page, I want something like this:

public MainPage()
    Config cfg = new Config();
    XDocument config = cfg.getConfig();
    //doing stuff with config here

The constructor for config calls readConfigAsnc and I have a method for the readcompleted that returns the xdocument. I want the readConfigCompleted called before execution continues in MainPage(). What is the best way to go about doing this?


The best way is to separate this out into two methods. Pass a function as a parameter of the getConfig, so like this:

cfg.getConfig( fcnToCall );

Later, in your code,

void fcnToCall( XDocument config )
    //Do stuff with config here...

Another option would be to use lambda expression if you want to retain your local variables:

Config cfg = new Config();
cfg.Callback += new Action<XDocument> action = s => 
            XDocument cfg = s as XDocument;
            //Do stuff with config here...

Need Your Help

Add class into last li of first level

jquery drop-down-menu

i'm working on styling my site's main menu and i would like to add a class to the first and last LI elements in the unordered list, but only the first and last items in the top level.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.