不能通过委托传递错误...
错误:
Object reference not set to an instance of an object.
代码:
RssReader.GetRssItems(IsUsePlainText,
url, ShowImages,
items =>
{
if (items.Any())
{
DataRSS.AddRange(items);
}
}, error => {
var s = error.Message; // Nothing is go here... :(
}
, OnFinally);
public static void GetRssItems(bool isUsePlainText, string rssFeedUrl, bool showImages,
Action<IEnumerable<RssFeedItem>> onGetRssItemsCompleted = null,
Action<Exception> onError = null, Action onFinally = null)
{
var webClient = new WebClient();
webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
{
try
{
if (e.Error != null) // report error
{
if (onError != null)
{
onError(e.Error);
}
return;
}
var stream = e.Result;
var response = XmlReader.Create(stream);
var feeds = SyndicationFeed.Load(response); // When something is wrong here an exception occurs
// do other stuff...
}
catch (Exception ex)
{
onError(ex); // ERROR HAPPENS HERE.... "Object reference not set to an instance of an object."
return;
}
finally
{
if (onFinally != null)
{
onFinally();
}
}
更新: