If it wasn't a UI element we were talking about here you'd still have to deal with some manner of synchronization primitive, which could have potentially been disposed of already (event occured during app shutdown) or a wait timeout resulting in a condition that needs to be handled. I won't argue that there isn't some opportunity for excellence on the part of the framework/runtime here, but thread synchronization and communication of any sort is going to require more care on the part of the developer regardless of language, platform, or API. It's been many years (~13) since I've written code for NeXTStep..er..OSX but I don't recall this problem space being substantially easier to manage there.
Control.InvokeRequired, tells you that some other thread, besides the current thread owns the window. You typically don't care about *which* actual thread it is that actually owns the window, but you do care that it gets the event, which is what Invoke()does for you. And, shocker, it's even in the documentation:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx
If it wasn't a UI element we were talking about here you'd still have to deal with some manner of synchronization primitive, which could have potentially been disposed of already (event occured during app shutdown) or a wait timeout resulting in a condition that needs to be handled. I won't argue that there isn't some opportunity for excellence on the part of the framework/runtime here, but thread synchronization and communication of any sort is going to require more care on the part of the developer regardless of language, platform, or API. It's been many years (~13) since I've written code for NeXTStep..er..OSX but I don't recall this problem space being substantially easier to manage there.
Or ObjectiveC and NeXTStep.
Control.InvokeRequired, tells you that some other thread, besides the current thread owns the window. You typically don't care about *which* actual thread it is that actually owns the window, but you do care that it gets the event, which is what Invoke()does for you. And, shocker, it's even in the documentation: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx
It could be something far less nefarious, for instance how do you measure mpg on a vehicle that doesn't run on a liquid or gaseous fuel (e.g. Solar)? Shell also manufactures solar panels: http://www.shell.com/home/content/shellsolar/about_shell/who_we_are_0129.html