Why cant a thread that is not the UI thread access the view?

后端 未结 3 1432
忘了有多久
忘了有多久 2021-01-22 07:22

I know that no thread can access the current view unless it is the UI Thread. I am wondering why? Why does it matter which thread is changing the view? Is it a security reason?

3条回答
  •  猫巷女王i
    2021-01-22 07:45

    Security isn't the only UI thread is the only thread that can access the Views. The main reason is that the code behind the views probably isn't thread safe. This means that there are no guarantees that data won't get corrupted if you have multiple threads reading and writing to common variables.

    Check out this great wikipedia article about thread safety.

提交回复
热议问题