Why in Windows a graphical element (es a Button in Winform) can be accessed only from the thread that created it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is due to the fact that most native windowing APIs, such as the Windows API, have thread affinity built in to allow the messaging to work properly, as the “messages” (such as input events) are processed in a queue within a single thread (ie: the message pump).
As such, the graphical elements that wrap this functionality, such as Windows Forms, inherit this limitation from their core API.
That being said, some frameworks don’t limit you in this fashion. For example, WPF allows data bound primitives to change from background threads, and the 4.5 build will even allow items within collections to be changed from background threads. The thread synchronization requirements get handled internally.