protection of common resource from multiple theads
hi -- I'm using .Net 4.0 and VS2010 with C#. I have a primary thread (the UI thread) which has in it a driver- handler to a USB based external device. I access the device so that only one post is outstanding at a time, which works fine by itself. I also have a background thread (a monitor thread) that needs to access the same external resource on a periodic basis. Where i run into trouble is with one thread posted and another overlaps the outstanding message.
I've played with various interlocking schemes, including using WaitOne, but i still have problems. So, I'm hoping you can suggest how this should work. I have a feeling i've been placing the WaitOne in the wrong place (I put it in the primary thread at the top of the driver call). I think it should go in the background thread with access controlled by set and reset in the primary code. is this correct? if so, how do i stop the foreground thread from accessing the resource while the background thread is using it? Do i use two WaitOne's with two different interlocks?