void ImageBrowserViewModel::StartMonthQuery(int queryId, cancellation_token token)
{
m_runningMonthQuery = true;
OnPropertyChanged("InProgress");
m_photoCache->Clear();
run_async_non_interactive([this, queryId, token]()
{
// if
query is obsolete, don't run it.
if (queryId != m_currentQueryId) return;
m_repository->GetMonthGroupedPhotosWithCacheAsync(m_photoCache, token).then([this, queryId]
(task<IVectorView<IPhotoGroup^>^> priorTask)
{
assert(IsMainThread());
if (queryId != m_currentQueryId)
{
//
Query is obsolete. Propagate
exception and quit.
priorTask.get();
return;
}
m_runningMonthQuery = false;
OnPropertyChanged("InProgress");
if (!m_runningYearQuery)
{
FinishMonthAndYearQueries();
}
try
{
// Update display with results.
m_monthGroups->Clear();
for (auto group : priorTask.get())
{
m_monthGroups->Append(group);
}
OnPropertyChanged("MonthGroups");
}
// On
exception (including cancellation), remove any partially computed results and rethrow.
catch (...)
{
m_monthGroups = ref new Vector<IPhotoGroup^>();
throw;
}
}, task_continuation_context::use_current()).then(ObserveException<void>(m_exceptionPolicy));
});
}