Using WPF and .NET 4.0.
I'm downloading some data using WebClient and using DownloadStringCompletedEventHandler to fire off my DownloadCompletedCallback function upon completion.
The issue I'm having is that when DownloadCompletedCallback is called I'm trying to set the contents of a label on the main form and am presented with the error.
An object reference is required for the non-static field, method, or property 'Armory.MainWindow.lblDebug'.
I understand that it's because the function DownloadCompletedCallback is declared as static but I don't understand why that matters.
Here's 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;
}
}