public bool RefreshDisplay()
{
Cache.ServiceLocator.GetInstance<IUndoStackManager>().Refresh();
var cacheCollector = new HashSet<IRefreshCache>();
var clerkCollector = new HashSet<RecordClerk>();
CollectCachesToRefresh(this, cacheCollector, clerkCollector);
foreach (var cache in cacheCollector)
cache.Refresh();
foreach (var clerk in clerkCollector)
clerk.ReloadIfNeeded();
try
{
// In many cases ReconstructViews, which calls RefreshViews, will also try to Refresh the same caches.
// Not only is this a waste, but it may wipe out data that ReloadIfNeeded has carefully re-created.
// So suspend refresh for the caches we have already refreshed.
foreach (var cache in cacheCollector)
{
if (cache is ISuspendRefresh)
((ISuspendRefresh)cache).SuspendRefresh();
}
// Don't be lured into simplifying this to ReconstructViews(this). That has the loop,
// but also calls this method again, making a stack overflow.
foreach (Control c in Controls)
ReconstructViews(c);
}
finally
{
foreach (var cache in cacheCollector)
{
if (cache is ISuspendRefresh)
((ISuspendRefresh)cache).ResumeRefresh();
}
}
return true;
}