uowzd01
uowzd01

Reputation: 1000

how to put return statement with ria asynchorous call

I have a method needs to return boolean value, inside my method I need to do an asynchronous call to decide either return true or false. I tried to put return statement inside lambda expression, but it throws a return type is 'void' error

bool method()
{
    domaincontext.Load(domaincontext.GetXXX(),
    loadOperation =>
    {
    value = ???
    }, null);

    return value;
}

Upvotes: 1

Views: 133

Answers (1)

Chui Tey
Chui Tey

Reputation: 5564

you cannot code like that. Silverlight will not allow you to query a web service and freeze the UI until the webservice returns. Silverlight's asynchronous model is more like javascript, where you make a call and when the result returns you can decide what you want to do with it.

One way is to change the code on the caller to look like this:

this.method(result => {
  if (result) {
     // Do something
  }
});

void method(Action<bool> continueWith)
{
    domaincontext.Load(domaincontext.GetXXX(),
    loadOperation =>
    {
        value = ???;
        continueWith(value);
    }, null);

    return value;
}

Upvotes: 1

Related Questions