troubleshooting Question

protection of common resource from multiple theads

Avatar of jdcoburn
jdcoburn asked on
.NET ProgrammingC#
4 Comments2 Solutions383 ViewsLast Modified:
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,
ASKER CERTIFIED SOLUTION
HooKooDooKu

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros