Avatar of jdcoburn
jdcoburn
 asked on

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?

thanks,
.NET ProgrammingC#

Avatar of undefined
Last Comment
Mike Tomlinson

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
HooKooDooKu

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
jdcoburn

ASKER
I can't get to either link.
Mike Tomlinson

?...they're working fine for me.  Are you behind a corporate firewall with some kind of filtering?

Here's another one:
http://www.dotnetperls.com/lock
Your help has saved me hundreds of hours of internet surfing.
fblack61