I am trying to write a WCF Servce which will reside in a Windows Service. This WCF Service will just add strings to a list and then the worker thread will process this list periodically. What is the best way to achieve this? I have read conflicting examples which has left me confused. What is the best way of the service and thread sharing a list object?
Update:
Thanks for the replies so far. Just to clarify, I am not struggling with the synchronization of the list or how to make it thread safe. That all seems the same principles as what I am used to in C++. What I am struggling with is where to define this list so it is accessible from both the WCF service and the worker thread. In C++ I would have created the list at global scope but C# doesn’t have a global scope. If I define it in the WCF service class, the thread can’t see it. If I definite it in the service class (where the thread function is defined and started) the WCF service cannot see it. I am sure I did something similar to this in ATL some time ago but it’s Friday afternoon and the grey cells have given up for the day.
Update2:
Where should I be defining the worker thread? In the Windows Service class (i.e. the host) or in the WCF Service? Should the WCF Service be a singleton service which has a list member and a thread function? That solves the access issue. Having done a lot of COM, I’m thinking of a WCF service as a COM component with the instance dying after it is accessed. This led me to want to put the static list and thread function in the Windows service class. That still feels the more natural place for it but perhaps I am just not thinking in a .NET way.
1) Create Windows Service
2) Host WCF in the WS ( http://msdn.microsoft.com/en-us/library/ms731758.aspx )
3) Make a thread synchronization ( http://www.albahari.com/threading/part2.aspx )
4) profits!