Hi all, My application has a navigation framework where each data entry screen is implemented as a usercontrol. Some of these UserControls are very large, and on slow systems can take a few seconds to construct.
In an attempt to speed things up, I'm considering caching these control instances instead of instantiating them each time I need them. In tests, this definitely seems to speed things up.
Very simplified, I'm essentially doing something like this:
public void Navigate(Type pageType)
{
Control page = GetOrCreatePage(pageType);
hostPanel.Clear();
hostPanel.Add(page);
}
private Control GetOrCreate(Type controlType)
{
if(!cache.Contains(controlType))
cache.Add(controlType, Activator.CreateInstance(type);
return cache[type];
}
My question is - should I be doing this? I'm only asking because I don't see many examples of this, and I've had to do a fair amount or refactoring and rethinking to support the control instances hanging around (managing disposal, event subscriptions, etc). I guess it just feels different so I want to make sure this is OK and I'm not stepping in something I'll smell later...
any feedback is appreciated.