I have adopted the following example from MSDN for incrementally loading thumbnails in a list view in an WinRT App:
https://code.msdn.microsoft.com/windowsapps/Data-Binding-7b1d67b5
I would like to remove the "await Task.Delay(10)" line below. When I do, I get a warning that the method lacks an await operator.
protected async override Task<IList<object>> LoadMoreItemsOverrideAsync(System.Threading.CancellationToken c, uint count)
{
uint toGenerate = System.Math.Min(count, _maxCount - _count);
// Wait for work
await Task.Delay(10);
// This code simply generates
var values = from j in Enumerable.Range((int)_count, (int)toGenerate)
select (object)_generator(j);
_count += toGenerate;
return values.ToArray();
}
I tried rewrite the method and wrap the entire method in a task asfollows:
protected async override Task<IList<object>> LoadMoreItemsOverrideAsync(System.Threading.CancellationToken c, uint count)
{
return await Task.Run(() => {
uint toGenerate = System.Math.Min(count, _maxCount - _count);
// This code simply generates
var values = from j in Enumerable.Range((int)_count, (int)toGenerate)
select (object)_generator(j);
_count += toGenerate;
return values.ToList<object>();
});
}
However, I am getting threading exceptions:
Exception: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
It seems like I need to run this on the UI Thread? But I don't have access to the Dispatcher.
Looking for some recommendations