I ran into a problem that I can't seem to figure out on my own. My program is an overlay for another application. It runs multiple windows forms in different threads. They all do everything on their own, but from time to time I need to update data in those forms (labels to be specific). The data for each form is unique, so I can't update all at the same time.
My best leads so far are this question, this and this. However, none of them deal with the problem of keeping track of the multiple instances of a window class. And that's where I need help.
The code looks like this right now:
> public class main {
>
> //This is the class, that organizes all the forms
> //and creates or updates them if needed. The forms are being created like this:
>
> new Thread(() => new Overlay(neededDataByOverlay).ShowDialog()).Start();
>
> }
>
> public class Overlay {
>
> //This is the overlay which I need to update from time to time.
> //Ideally I would like to call a method update(dataThatNeedsToBeUpdated) so it can update itself.
> //There will be multiple instances of this class at the same time.
>
> }
My question is, how can I keep track of the different forms in the different threads and then call that method in them? Is it possible to create a list with threads inside or can I somehow put the running forms into a list? I need to identify each window by a name or something to get the right data to the right window. I am really stuck with this one and would appreciate any help.
Edit: Apparently it is not clear what my intention is with this program and why the forms need to be in separate threads. Those forms are overlays for stock trading programs. They display additional information dependent on the used program or the currently opened windows. For instance, one window of the stock trading program shows currency-exchange rates, so the overlay shows additional information related to the currency, that the stock trading program doesn't out of the box. Then another window is showing stock prices in realtime and the overlay displays additional information on top.
The overlays (forms) are constantly resizing and adjusting themselves dependent on the position of the underlying windows (and are actually doing some calculations), that is why they need to be in their own thread. Otherwise the resizing timers and calculation methods of the forms would block the main thread. The main class of my application fetches data from a specific server, whenever there is a new dataset available. So, for example: As soon as a new dataset for currency-exchange-rates is available, it gets processed and the specific overlay needs to be updated.
Now, what is the best way to keep track of all the forms(e.g. form1.purpose = currency, form2.purpose=stocks) and update them in their threads with the new datasets that my main thread is fetching in set intervals?
I am very sorry, if this doesn't answer your questions, I tried my very best to explain this particular problem.