Check if resourse is locked

  • Thread starter Thread starter bg_ie
  • Start date Start date
B

bg_ie

Hi,

I have the following in my com object-

static public uint Time
{
get
{
lock (Channel.staticLockObject)
{
return Channel.time;
}
}
}

Sometimes though I am getting back incorrect values when using Time.
How can I check if Channel.staticLockObject is already locked so that I
can print a debug message?

Thanks for your help,

Barry.
 
Barry,

What do you consider to be "incorect values?"

Your use of locking here doesn't make much sense. You should lock when
you're changing or updating a shared value, not just when you're getting a
shared value. What your locking does here is ensure that no two threads can
GET the time at the same time, however, you could have a thread that updates
the time at the same time that a thread is getting the time, resulting in
two different values when you expected one.

Can you give us more detail as to what you're trying to do and maybe we can
be more helpful.

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top