Something like this....
if ( myObject is locked)
{
return alreadyRunning;
}
lock(myObject)
{
\\ do work
}
return didWork;
Any direction is deeply appreciated
Thanks
Nalaka
Try look at Monitor.TryEnter !
Arne
Instead of using lock, you will want to call the TryEnter method.
Because you will acquire the lock manually, you have to be sure to release
it as well. You will want something like this:
// Was the lock acquired?
bool lockAcquired = false;
// Enter try/finally.
try
{
// Try to acquire the lock.
if (!(lockAcquired = Monitor.TryEnter(myObject)))
{
// Get out.
return;
}
// Do your work here.
}
finally
{
// If the lock was acquired, then exit.
if (lockAcquired)
{
// Release the lock.
Monitor.Exit(myObject);
}
}
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Nalaka" <nala...@nospam.nospam> wrote in message
news:%23mRnXkI...@TK2MSFTNGP03.phx.gbl...
something like this.....
if ( isAlreadyLocked )
{ return anotherThreadIsAlredyAtWork }
lock ( myObject )
{
// do the work
}
Any help is appreciated
Thanks
Nalaka
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Nalaka" <nala...@nospam.nospam> wrote in message
news:ucPrZ7Qr...@TK2MSFTNGP03.phx.gbl...
sorry again
Nalaka
"Nicholas Paldino [.NET/C# MVP]" <m...@spam.guard.caspershouse.com> wrote in
message news:eFVNECR...@TK2MSFTNGP02.phx.gbl...