Hi I have a Architecture question.
(Put the text on courier new font to understand the graphic)
Imagine that you have the next objects:
A = Form
B = Panel
C = ButtonEx inherit from Button
D = BUtton
Then when the program start the objects are allocated on the next Way
------- ------- ------- -------
| ----->| ------>| <====>| |
| A | | B | | C | | D |
| | | | | | | |
------- ------- ------- -------
When the application start:
Load form A
Form A add the Panel B
Panel B add Button C
D Functionality is "close" the panel B.
D Can't be added to Form A has to be part of B
Case 1)
Application is Stable and working.
Case 2)
When you press the Button D send a signal (event) to A.
A Dispose B and B is remove from Controls A
Here is the problem:
Some times, may be once a day, the application HANGS.
Debugging I could see that A Dispose B but after the signal,
the program has to come back to D to finish the method.
And I guess D is invalid because is already Disposed.
Case 3)
When you press the Button D send a signal (event) to A.
A DON'T Dispose B and B is remove from Controls A
Here is the problem:
Some times, may be once a day, the application HANGS.
Debugging I could see that A DON'T dispose B but after the signal,
the program has to come back to D to finish the method.
And I guess D is already take by the GC because the
reference A <-> B was deleted.
So, the question is how D can inform to A that A has to
remove B in a secure way?.
1) D when signal (push button) set a Flag on A, A has a timer
and check for this flag, if this flag is ON then remove B
(Too tricky and I don't like the idea)
2) A has another thread running on low priority.
and it is waitingForSignalObject.
D Signal A and the thread Dispose and Remove B object from A.
This can work and I had many B object of different king,
then I can have a justification to add another thread to do this, because is
going to check for multiples Signals.
The only cons is the signal from D has to be last last sentence
on the complete cycle (B, C, D).
Then the question is, somebody knows how to do this king of
things with out add a thread only for checking and disposing?
Thanks.
Gustavo.