how to access gui controls from a background thread?

  • Thread starter Thread starter assaf
  • Start date Start date
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
 
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
 
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
 
Back
Top