How to use a mutex
I have one thread, that is sending data stored in a buffer of type List< string> via tcp. Another thread is writing into the buffer. As I am not very familiar with c# I'd like to know how I should use lock or Mutex correctly. This is the code I'd like to use eventually: while(buffer.isLocked()) { buffer.wait(); } buffer.lockBuffer(); buffer.add(tcpPacket); buffer.unlockBuffer(); buffer.notify(); This is my current code. I hope someone can help me complete it. public class Buffer { private Mutex mutex; private List<string> buffer; private bool locked = false; public Buffer() { mutex = new Mutex