Why can I access controls from a form in a thread without cross thread exception?

前端 未结 3 1893
旧巷少年郎
旧巷少年郎 2020-12-22 08:52

Usually, when you access controls in a Thread you end up with some cross thread exceptions. In my C# WinForms Application I have a picture box and a toolstriplabel which do

3条回答
  •  执笔经年
    2020-12-22 09:08

    You won't get cross thread exception, but it doesn't mean that this is a safe operation. There is always a possibility for your control to go unstable. You just don't know when it will happen.

    See the following explanation from Microsoft. http://msdn.microsoft.com/en-us/library/ms171728.aspx

    Access to Windows Forms controls is not inherently thread safe. If you have two or more threads manipulating the state of a control, it is possible to force the control into an inconsistent state. Other thread-related bugs are possible, such as race conditions and deadlocks. It is important to make sure that access to your controls is performed in a thread-safe way.

提交回复
热议问题