how to access gui controls from a background thread?

A

assaf

hi all

i am accessing my gui controls only from the thread that created the
winform.
i am using ISynchronizeInvoke.BeginInvoke()
however, much of the gui manipulation in my app is low priority,
and should not interfere with the user experience.

when the user wants to interact with the gui,
that should be in the original thread at a normal priority.
but when the app wants to update the gui,
that should be in a low priority background thread.

how can i access gui controls from a background thread?
(without ISynchronizeInvoke.BeginInvoke())


assaf
 
G

Guest

Hi assaf,

You are not supposed to access GUI controls from a thread other than it's
creator. For accessing these, you need to use the Control.Invoke method and
should also check whether you are on the right thread with the InvokeRequired
property.

Have a look @ this article on thse lines:
http://msdn.microsoft.com/msdnmag/issues/03/02/multithreading/

Let me know if you need more assistance.

HTH,
Rakesh Rajan
 
R

Richard Blewett [DevelopMentor]

I'd always prefer BeginInvoke over Invoke as you rarely need the thread to wait for the UI update to have occurred before it procedes and depending on your design you leave a door open to thread deadlocks. But, as you say, under no circumstances, none whatever, no - really - none at all, should the background thread touch the UI.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hi assaf,

You are not supposed to access GUI controls from a thread other than it's
creator. For accessing these, you need to use the Control.Invoke method and
should also check whether you are on the right thread with the InvokeRequired
property.

Have a look @ this article on thse lines:
http://msdn.microsoft.com/msdnmag/issues/03/02/multithreading/

Let me know if you need more assistance.

HTH,
Rakesh Rajan
 

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

Top