I initialize a string, then I set it to something else, I later get it and print it with a button click BUT the first time I click the button I get the original string " ". A few seconds later I click again and this time the string is the new modified one (which I want). Why would this happen?
string addy = " ";
public void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string addy = e.Result;
SetName(addy);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
WebClient client = new WebClient();
client.DownloadStringCompleted += ClientDownloadStringCompleted;
client.DownloadStringAsync(new Uri("http://www.google.com"));
string synop = GetName();
textBlock1.Text = synop;}
public string GetName()
{
return addy;
}
public void SetName(string name)
{
addy = name;
}