Worker thread updating Forms's field value

  • Thread starter Thread starter Walter W
  • Start date Start date
W

Walter W

Hello,

I have a ordinary Form that has disabled editfield for status information
and bushputtons
for doing actions.

For Example pushing Fetch pushbutton starts a query for retrieving
information from database.
I also have a sub Thread that should same time update disabled editfield in
certain interval.

I have noticed this couple times before especially in MFC programs but also
in
C# programs. When Form's (main) Thread is fetching data from database that
sub Thread
which should update disabled editfields sets values to editfields but those
new values does not
appear into editfields... same old value is still there,

So, can anyone remember what was reason for that and how should this kind
thing should
be coded? Thanks for any help.

Cheers!
 
Walter W said:
C# programs. When Form's (main) Thread is fetching data from database that
sub Thread
which should update disabled editfields sets values to editfields but those
new values does not
appear into editfields... same old value is still there,

You can't update the UI from a background thread - you have to cause any
actions that need to update the UI to occur on the UI thread, via (for
example) Control.Invoke().

To get that to work, the UI thread needs to be pumping messages: i.e.
either not busy or periodically calling Application.DoEvents()

I'd recommend performing the DB operations on the background thread
instead, since they'll likely be blocking due to network effects etc.,
but of course be aware that it is a more complicated application model
to get right.

-- Barry
 
http://channel9.msdn.com/ShowPost.aspx?PostID=171594

--
William Stacey [MVP]

| Hello,
|
| I have a ordinary Form that has disabled editfield for status information
| and bushputtons
| for doing actions.
|
| For Example pushing Fetch pushbutton starts a query for retrieving
| information from database.
| I also have a sub Thread that should same time update disabled editfield
in
| certain interval.
|
| I have noticed this couple times before especially in MFC programs but
also
| in
| C# programs. When Form's (main) Thread is fetching data from database that
| sub Thread
| which should update disabled editfields sets values to editfields but
those
| new values does not
| appear into editfields... same old value is still there,
|
| So, can anyone remember what was reason for that and how should this kind
| thing should
| be coded? Thanks for any help.
|
| Cheers!
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top