Using WPF and .NET 4.0.
I load some data using WebClient
and using DownloadStringCompletedEventHandler
to disable the function DownloadCompletedCallback
after completion.
The problem I am facing is that when DownloadCompletedCallback
I call, I try to set the contents of the label in the main form and present an error.
An object reference is required for a non-static field, method or property "Armory.MainWindow.lblDebug".
I understand that this is because the function is DownloadCompletedCallback
declared as static, but I do not understand why it matters.
Here is the code I'm using.
public static void DownloadHTML(string address)
{
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadCompletedCallback);
client.DownloadStringAsync(new Uri(address));
}
private static void DownloadCompletedCallback(Object sender, DownloadStringCompletedEventArgs e)
{
if (!e.Cancelled && e.Error == null)
{
lblDebug.Content = (string)e.Result;
}
}
source
share