This method is called from wpf main thread. Throwing - Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task' error. What am I doing wrong? DocCollection is of type ObservableCollection.
Task TaskProcesQueue(SynchronizationContext _SyncContext)
{
return Task.Run(() =>
{
if (DocCollection != null)
{
foreach (var item in DocCollection.ToList())
{
ProcessCurrentDocument(item);
var t = Task.Run(() => DocCollection.Remove(item), _SyncContext));
}
}
});
}
Task.Runto remove an item from a collection (assuming the collection is of reasonable size) is redundant. - Yuval ItzchakovRemovedirectly would do it in the background thread, and would cause any events raised by it to run in the background thread as well. Now, what the OP has in the question isn't entirely the right way to do it, hence the error message, but the way you're suggesting isn't either. - user743382Removeon the UI thread, consider my comment void :) - Yuval Itzchakov