Imagine the following situation:
A method from object "A" creates "n" threads.
Variables from these threads contains values that should be updated to a form (only when this form exists), one form can be shown/created for each thread. Thought the forms might not exist, the threads will be always running.
I dont want to control the components (eg. labels) of the form from the threads because if I do so, they must exist otherwise we get an NullReferenceException.. and also dont want to create them all and leave them "invisible" because this would be a waste of memory (imagine if we have 20 forms). Because of this (we dont know when the form will be created), we cant invoke its components also.
My idea was to create an "in-the-middle" object with all variables (that must be updated in the form) being changed from the threads , and make this object raise an event when there is a change, so that an event handler in the form's code will update these values to the form's labels/controls. What do think? so maybe I wouldnt need the threads handling all the controls directly.
The forms are in a separate class, then how do you create an event handler of these threads that you dont even know the names (because it was instanciated in another class)? or how do you manipulate this object from outside (once we dont have the reference to it there)?
As Microsoft says:
A delegate is an object that you can use to call a method of another object.. but what about getting variables or thread's variables?
thank you for your attention.