So what do you think is the best way to prevent multiple threads of a C# Windows service running simultaneously (the service is using a timer with the OnE
If all you want is to prevent two threads in the same process/app domain from executing concurrently, the lock statement will probably do for you.
But note that lock leaves the other threads, well, locked while they wait for access to the critical section. They are not aborted or redirected or anything; they are sitting there, waiting for the original thread to finish execution of the lock block so they may run.
A mutex would give you greater control; including the ability to have second and subsequent threads just stop altogether, rather than locking, and locking threads across processes.