I have been asked to put a constraint that users should not be able to concurrently execute part of the code that calls C++ unmanaged code from ASP.Net/C# web application.
I wanted to ask if placing lock(someobject) around the C# code which is in a C# class library that calls the PInvoke/C++ code is sufficient to ensure that only one user will be able to execute the code? or is there another technique?
I might have to host this code as a WCF service. Would this approach would work too?
If you use WCF you can adopt ConcurrencyMode.Single, which will automatically ensure that only one thread is performing an operation at any given moment within one context instance.
Else you would need to use manual thread syncronization (as lock, mutex etc.).