I don't have a problem (yet), since my application works, but I want to understand what's going on so I don't get into trouble later. (I'm primarily a database/web application programmer, so threads aren't normally my thing!)
Short version: does the UI need to lock form data when multiple threads are updating it?
I have a simple Winforms application (using DataGridViews) that scans files for certain content and displays the results to the user. I at first did this all in the UI thread but learned that was not a good idea and settled on using ThreadPool.QueueUserWorkItem for [ProcessorCount] collections of items. This works fine, using delegates and BeginInvoke functionality to fire results to the UI as they are found. (Though sometimes there are too many results and the UI still lags, but that's another problem.)
The worker threads are completely isolated, doing their own thing. I understand the concept of multiple threads and needing to be aware of accessing shared data at the same time. What I'm not entirely clear on, however, is what happens when the various threads call the UI thread to update it. Only the UI will be updating controls (and form-level variables) but since the calls come from the other threads, how does this play out? For example, if I'm adding items to a List or incrementing a counter, can a call from one worker thread interrupt another? Each BeginInvoke is it's own call, but modifying the data seems like it could still be a problem.
None of the examples of BeginInvoke I've found mention any need for locking in the UI. These two topics are related but still don't give the exact answer I'm looking for: