As mentioned earlier, a provider refresh is a process of retrieving and caching tasks for a user. It is done on demand, with no background job processing the tasks. Refresh will be started at that moment, when a user access its “My Tasks” area. There is an artificial limit of 5 minutes between provider refreshes, which can be changed through PowerShell for SharePoint on premise.
Provider refresh can also be initialized programmatically, from the task session:
CreateRefreshJobResult refreshResult = uos.BeginCacheRefresh();
The resulting CreateRefreshJobResult will tell us if the provider refresh process has started successfully (it will be probably not yet completed). If the provider refresh process could not be started from some reason, CreateRefreshJobResult will hold the error information and it’s Correlation Id (mostly caused by the imposed 5 minutes limit).
If CreateRefreshJobResult was executed successfully, it will contain an Id of the newly created provider refresh process, which can be used to check the provider refresh job status. You can check the general status, the status for each task provider separately, and update status for each task location separately.
This short code snippet explains it all:
RefreshResult rr = uos.GetRefreshStatus(jobId); Console.WriteLine("Refresh state: " + rr.AggregatorRefreshState.ToString()); Console.WriteLine("Corellation id: " + rr.CorrelationId); Console.WriteLine("Refresh finished: " + rr.RefreshFinished.ToShortDateString() + " " + rr.RefreshFinished.ToShortTimeString()); Console.WriteLine(""); Console.WriteLine("Provider statuses:"); Console.WriteLine("------------------"); foreach (ProviderRefreshStatus prs in rr.ProviderStatuses) { Console.WriteLine("Provider key: " + prs.ProviderKey); Console.WriteLine("Provider name: " + prs.ProviderLocalizedName); Console.WriteLine("Root location id: " + prs.RootLocationId.ToString()); Console.WriteLine("Provider Refresh started: " + prs.RefreshStarted.ToShortDateString() + " " + prs.RefreshStarted.ToShortTimeString()); Console.WriteLine("Provider finished: " + prs.RefreshFinished.ToShortDateString() + " " + prs.RefreshFinished.ToShortTimeString()); Console.WriteLine(""); }
Console.WriteLine(""); Console.WriteLine("Location update results:"); Console.WriteLine("------------------------");
foreach (LocationUpdateResult lur in rr.TaskChangesByLocation) { Location loc = allLocations.Where(a => a.Id == lur.RootLocationId).FirstOrDefault(); Console.WriteLine("Location: " + lur.RootLocationId); Console.WriteLine("Added: " + lur.AddedCount.ToString()); Console.WriteLine("Active added: " + lur.ActiveAddedCount.ToString()); Console.WriteLine("Removed: " + lur.RemovedCount.ToString()); Console.WriteLine("Updated: " + lur.UpdatedCount.ToString()); }
The result from this code snippet will look like the screenshot below. We can see, that there is only one provider active (SharePoint, in this case), and that 3 tasks have been updated in the location with id 3:
You can retrieve a provider refresh history for a user, with all provider refreshes from some time interval until now.
Those few lines of code will enable you to check refresh status for the past 7 days, and to analyze potential problems – for each unsuccessful provider refresh, Correlation Id associated with the refresh status, for the further analysis.
RefreshHistory rh = uos.GetRefreshHistory(DateTime.Now.AddDays(-7));
foreach (RefreshResult rr in rh.Refreshes) { // Check refresh status }