By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,182 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,182 IT Pros & Developers. It's quick & easy.

Worker thread updating Forms's field value

P: n/a
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!
May 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Walter W" <jw****@hotmail.com> wrote:
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
May 12 '06 #2

P: n/a
Yes the other thread should be pushing the request to the main thread to
touch the controls. Windows controls should only be dealt with fromt he main
thread see http://msdn2.microsoft.com/en-us/library/zyzhdc6b.aspx ...
http://weblogs.asp.net/justin_rogers...es/126345.aspx includes an in
depth discussion.

Cheers,

Greg Young
MVP - C#

"Walter W" <jw****@hotmail.com> wrote in message
news:e4**********@nyytiset.pp.htv.fi...
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!

May 12 '06 #3

P: n/a
http://channel9.msdn.com/ShowPost.aspx?PostID=171594

--
William Stacey [MVP]

"Walter W" <jw****@hotmail.com> wrote in message
news:e4**********@nyytiset.pp.htv.fi...
| 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!
|
|
May 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.