Cross Threading between UI and Background Thread
I've written a program that allo开发者_如何学运维ws the user interface thread to access a populated array at almost any time. This array is populated by a separate background worker thread within an object.
What will happen when the user interface thread accesses this array? Will it automatically lock it down before accessing it?
I'm writing my code in managed C++/CLI.
Array is not locked automatically. If it is accessed from multiple threads, it is your responsibility to provide synchronization.
Another way is to serialize array update from a worker thread(s) through Control.BeginInvoke call - in this case array is accessed/changed only from UI thread, and synchronization is not needed.
精彩评论