ozbear said:
I think you are over analyzing this.
Well, you're certainly welcome to your opinion.
I merely had a large number of
components dropped on for a test/throwaway program that I needed to
collect references to in an array for easier manipulations of them.
No long, drawn out analysis of the "best" way to do this was required,
just whether or not it was possible. You say no, for
BackgroundWorkers anyhow, and that's fine, thanks.
If you don't mention that you're not writing a real program, why should
anyone else make the assumption that you're not? The fact is, under
ordinary circumstances, my points are valid. If you're writing garbage
code, then obviously "anything goes", but you can't expect people to be
mind-readers and know that without you mentioning it.
Of course, for that matter, if this is just "throwaway" code, what's the
big deal? Just put the things in an array. If you've got time to drag
them into the form, you've got time to do that. Or just use reflection;
even if that's almost always the wrong way to do something, it doesn't
seem to matter in this case whether this is implemented in the wrong way
or the right way.
The fact that (you say) that other components, such as Timers, do get
placed in the Components collection would seem to belie the notion
desiring to iterate over non-Control components is questionable
practice.
Actually, having thought about it some more, I realize that probably the
reason Timer instances are tracked and BackgroundWorker instances aren't
is because the former implements IDisposable, and the latter does not.
More generally, the "components" collection is used by the
Designer-generated code to properly dispose components when the form's
Dispose() method is called.
In other words, the "components" member isn't there for your benefit,
it's for the Designer-generated code's benefit. I don't see how its
presence should in any way be construed as an indication that it makes
sense normally to iterate all the component instances you add to a form.
And of course, in abnormal circumstances when it does make sense, you
can just create your own array or other collection and track them that way.
For all we know, it is a bug in the framework that other
components types are not present in that collection, or that timers
are. Either way, inconsistency is rarely a good thing.
See above. On further reflection, I believe that the behavior is
consistent and likely completely intentional.
Pete