I'm getting "An object reference is required for the non-static field, method, or property 'System.Windows.Threading.Dispatcher.BeginInvoke(System.Action)'" for this code.
private void ResponseCompleted(IAsyncResult result)
{
HttpWebRequest request = result.AsyncState as HttpWebRequest;
HttpWebResponse response = request.EndGetResponse(result) as HttpWebResponse;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
Dispatcher.BeginInvoke( () => {
try
{
XDocument resultsXml = XDocument.Load(sr);
QueryCompleted(new QueryCompletedEventArgs(resultsXml));
}
catch (XmlException e)
{
XDocument errorXml = new XDocument(new XElement("error", e.Message));
QueryCompleted(new QueryCompletedEventArgs(errorXml));
}
});
}
}
}
Things have changed a bit since the last answer was posted for this question.
System.Windows.Threading.Dispatcher.BeginInvoke
is now Deployment.Current.Dispatcher.BeginInvoke