G
Guest
Hello all,
I am experiencing a problem with a compact framework program I am writing
where the program freezes if an attempt is made to update or read any of the
properties of controls on forms which are not visible (hidden behind forms
which have been opened on top of them). This is the specific order of events:
1. The user clicks on a button on one of my forms, which causes a new form
to be shown which monitors the progress of a web service call. The web
service call is performed in a separate thread.
2. This web service call collects some data from a remote service, and this
data is used to update some internal data structures, which are bound to GUI
components on the original form (TextFields in this instance though
potentially any common Control type). The data structures implement
IEditableObject to allow changes to be picked up by bound controls.
3. Changes to the data provokes the bound control to copy the changes,
raising one of the many changed events. In this case, a TextChanged event is
raised.
4. I have a TextChanged listener on the control that checks the contents of
the field to see whether it is valid or not. An invalid field has it's
background colour set to pink, a valid one to Color.Empty.
5. Attempting to set the colour on the control results in the program
freezing.
I have tried to fix the problem in various ways, including making the update
within an EventHandler delegate which is called through Control.Invoke, to no
avail. Even querying properties on the control (which I thought was supposed
to work even if you weren't within the correct thread for the control) causes
the hang - I thought that perhaps since the control wasn't visible (and hence
the Visible property should be false) that I could check the Visible property
and if false, not perform the colour update.
Is there anything inherently wrong with modifying the state of a control on
a form which is currently hidden behind one in front? I am currently trying
to see how I could change my code to defer handling the change events until
the form becomes visible again without some filthy hacks.
Any advice would be appreciated.
I am experiencing a problem with a compact framework program I am writing
where the program freezes if an attempt is made to update or read any of the
properties of controls on forms which are not visible (hidden behind forms
which have been opened on top of them). This is the specific order of events:
1. The user clicks on a button on one of my forms, which causes a new form
to be shown which monitors the progress of a web service call. The web
service call is performed in a separate thread.
2. This web service call collects some data from a remote service, and this
data is used to update some internal data structures, which are bound to GUI
components on the original form (TextFields in this instance though
potentially any common Control type). The data structures implement
IEditableObject to allow changes to be picked up by bound controls.
3. Changes to the data provokes the bound control to copy the changes,
raising one of the many changed events. In this case, a TextChanged event is
raised.
4. I have a TextChanged listener on the control that checks the contents of
the field to see whether it is valid or not. An invalid field has it's
background colour set to pink, a valid one to Color.Empty.
5. Attempting to set the colour on the control results in the program
freezing.
I have tried to fix the problem in various ways, including making the update
within an EventHandler delegate which is called through Control.Invoke, to no
avail. Even querying properties on the control (which I thought was supposed
to work even if you weren't within the correct thread for the control) causes
the hang - I thought that perhaps since the control wasn't visible (and hence
the Visible property should be false) that I could check the Visible property
and if false, not perform the colour update.
Is there anything inherently wrong with modifying the state of a control on
a form which is currently hidden behind one in front? I am currently trying
to see how I could change my code to defer handling the change events until
the form becomes visible again without some filthy hacks.
Any advice would be appreciated.