Could anyone please help me to update the single UI thread with multiple downloading threads? in C# with WinRT.
I’m currently using Task.Run. It works, but since it spreads to multiple threads processing, the program failed to update the single UI properly.
Method UpdateRSSItemAsync() downloads the content (it’ll updates RSSItemList) that is binding to UI (ListView).
Thank you,
Program runs fine in sequential order
// Run multiple tasks in sequential order
foreach (SyndicationItem item in CurrentFeed.Items)
{
if (m_bDownloadInterrupted)
break;
RssItemList = await UpdateRSSItemAsync(CurrentRSSDataGroup, RssItemList, CurrentFeed, item);
}
However, failed to update UI if running in multiple threads
// Run multiple tasks in multiple threads
foreach (SyndicationItem item in CurrentFeed.Items)
{
if (m_bDownloadInterrupted)
break;
RssItemList = await Task.Run<List<RSSItem>>(async () =>
{
RssItemList = await UpdateRSSItemAsync(CurrentRSSDataGroup, RssItemList, CurrentFeed, item);
return RssItemList;
});
}
Use
Task.WhenAnyor Stephen Toub’sInterleaved:You may find my
async/awaitintro post helpful.