The problem here is not thread safety. All methods are "thread safe" because they do not damage the state of the application when called on several threads at the same time - this is that thread safety includes the exception of the wrong thread (I don’t remember what it's called).
What they have is an afinity thread - they can only be called in one thread, sometimes called a user interface thread, although this is misleading because it means there is only one. This is mainly due to the fact that the OS calls on which they depend have the same flow binding rules.
Believe me, that’s good. When you think about the main role of UI Thread, everything starts to become clear. The task of user interface flows is to receive input from users ’hands, using the keyboard or mouse, act on it and produce output in the form of pixels in response. There is only one user, and this user has only one set of eyes. The user expects to see everything they do on the screen, and most importantly, they expect it to happen in the order in which they did it. A multi-threaded user interface will make this very difficult to achieve - almost impossible.
The problem is that when you mix workflow threads with the user interface thread, you need to make a certain amount to talk to the user interface because you have to be in the user interface thread to do this. Again, as I said, this is good. Someone must do this, otherwise the user will see that everything is happening in the wrong order, and this is bad. The system can, admittedly, do it for you, as well as in some WIN32 calls, but it has problems. First of all, the system cannot know what granularity you need for sorting, so you may be ineffective. Your operations can be better distributed at a higher level than the system can understand. Secondly, marshalling is expensive, and it punishes developers who do the right thing and correctly port everything to the user interface. Thus, the system does everything possible, checks whether it is in the correct thread, and if not, throw an exception.
source share