problem: I'm going to write service app, which will monitor set of directories. This service app will be controlled from external application using windows messages (e.g. for changing directory to monitor). It seems to be necessary to use 2 threads - one for service itself [Main] and another for real processing [Process], because it will need to do kind of full scan of directory, and that might be time-consuming, especially over the network. The idea is to have TList [FIFO IIRC]: Main will add user requests to the end of the list and Process will take items out of the list one by one starting from first one and execute them.
How to synchronize usage of TList? Seems that list should be locked when item is being added [Main] and removed [Process]. What's the best way to do that? Process thread will lock list, get item, update list, unlock it and then process the action, so list (hopefully) will not be locked for a long time. How to handle a situation when the list is locked by Process and WM arrives to Main?
Also what is the best way to check the list for new items in Process Thread?
Code samples would be fine.