How to get OpenReadCompleted result from method

I want get a result from webClient_OpenReadCompleted, and i want get response in getMethod. But in this code, at first getMehod works and only then, when getMethod finished, webClient_OpenReadCompleted works. How to get a result in getMethod?

p.s. It's all on Windows Phone

public string apiUri = "https://api.vk.com/method/";
public string response = "";

public void getMethod(string parameters)
{
    var webClient = new WebClient();
    webClient.OpenReadCompleted += webClient_OpenReadCompleted;
    string uri = apiUri + parameters + "&access_token=" + access_token;
    webClient.OpenReadAsync(new Uri(uri));
}

void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    XDocument xml = XDocument.Load(e.Result);
    response = xml.ToString();
}

public void statusGet(string uid)
{
    getMethod("status.get.xml?uid" + uid);
}

Answers


if you want to return data, I would suggest you set up 1) Custom EventArgs to hold data 2) Custom event.

When you get the data, you set the event args and then set the event so subscriber gets the data.


I didn't try it, but i asked one Senior c# Developer and he advised to create bool and write this:

bool work;

public void getMethod(string parameters)
{
    var webClient = new WebClient();
    webClient.OpenReadCompleted += webClient_OpenReadCompleted;
    string uri = apiUri + parameters + "&access_token=" + access_token;
    webClient.OpenReadAsync(new Uri(uri));
    work = true;
    while(work) { Thread.Sleep(100); }
}

void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    XDocument xml = XDocument.Load(e.Result);
    response = xml.ToString();
    work = false;
}

Now, question is not actual, because i changed the architecture of my app.


Need Your Help

Android. that this does not work well? is a bug? SetMargins

android android-layout layoutparams

By setting the margins to zero the image fills the screen. But to set the margins to one hundred, it fits all right except the right side. Why do it?

Read web.config from javascript

javascript asp.net

I am unable to read by web.config. My web.config is as below