2

I have been developing many softwares using C# .NET and Android. I have noticed that both systems have the same behaviour on Thread upon UI control (Label/TextView, etc...). And for that, I don't think it is just coincident for the design to prevent changes outside of thread.

The most popular problem people are having is that they cannot be changed (say, Text property) outside of the thread they were created. We must either use Invoke in C#, or use Handler in Android.

My question is, WHY do controls have to implement such behaviour? What bad may happen if I could change their property/field outside of the thread they were created?

EDIT: Thanks Raghunandanless for your reference. I have already known parts of it, and my main concern for this question is, why thread from a thread pool aren't running on your UI thread cannot access control's properties/fields? The Android's View are actually just POJO, am I correct? If so, I think any thread can access them with no problem. Please clarify if I said anything wrong.

4

1 回答 1

1

出于同样的原因,在大多数标准库中默认情况下集合是非同步的:

  1. 因为大多数时候你自然地在单线程中工作并且不想支付同步价格
  2. 同步小部件的方法是不够的,因为要自动更新两个相关的小部件,您必须首先锁定两者。但是如果你这样做,那么同步方法只是浪费代码和时间。
于 2013-08-15T08:21:53.723 回答