I would like to use the Task framework in .NET to schedule something to run on a different thread then when it's done continue with an operation to update the UI on the UI thread. (I haven't played with it much yet, so it's not very familiar to me.)
Here is the code:
Task<List<NewsItem>> fetchTask = new Task<List<NewsItem>>(() =>
{
List<NewsItem> items = Rss.FetchNewsItems(feed);
return items;
}).ContinueWith(x => UpdateNewsItems(x.Result),CancellationToken.None,TaskContinuationOptions.None,scheduler);
private void UpdateNewsItems(List<NewsItem> items)
{
...
}
Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'System.Threading.Tasks.Task<System.Collections.Generic.List<Spark.Models.NewsItem>>'. An explicit conversion exists
I thought that if I use the generic signature of List<NewsItem> on the task that the Task.Result would return that type so I could pass it to my method... What am I doing wrong here?