Matias Woloski <[EMAIL PROTECTED]> wrote:

> Thanks for the quick reply Barry.
> 
> > To what purpose do you keep a mapping of strings to components? I think
> > knowing the answer to this question would help people solve your
> > problem.
> >
> I actually simplified the problem and made it agnostic of the technology.
> What I'm really keeping in that dictionary is <UIElement, ElementHost>. More
> context: ElementHost is the way WPF provides to integrate WPF controls (they
> all derive from UIElement) within Winforms apps.
> Basically what I want to achieve (using other components in the equation) is
> hiding the user the complexity of ElementHost to ease the Winforms to WPF
> migrations.

OK, so if I understand it, you're creating a mapping of values of type X
to values of type Y where you don't control either type and thus can't
e.g. add a pointer.

> Regarding the periodic scans I can do that proactively. If you ask for a
> specific key I get the WeakRef and check if the Target is null, if it is I
> will remove it from the inner dictionary.
> 
> private Dictionary<TKey, WeakReference> inner = new Dictionary<TKey,
> WeakReference>();
> 
> public TValue this[TKey] {
> get {
>   object target = wr.Target;
>   if (target == null)
>   {
>      inner.Remove(key);
>   }
>   return target;
> }
> 
> What do you think?

It seems reasonable, assuming that either every key will be looked up at
some stage, or the UI won't be running indefinitely with large churn in
objects. And don't forget that the dictionary will keep the keys alive
:)

-- Barry

-- 
http://barrkel.blogspot.com/

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to