Brief When working with a multithreading application it is very important for developers to handle multiple threads for a critical section of code. Monitor and lock is the way to provide thread safety in a multithreaded application in C#. Both provide a mechanism to ensure that only one thread is executing code at the same time to avoid any functional breaking of code. Example Lock for only one request to be processed at a time. private static object s_SyncRoot = new object (); ... new Task (() => { lock ( s_SyncRoot ) { // process payment - single thread } }). Start (); return "ok" ; Links StackOverflow Monitor And Lock In C#
This blog consists of the content that has been experienced by me at different age or different stages of my life. If any complain about any post please contact me. I will remove as soon as possible.