Yes, the lock keyword is a terribly named keyword
http://www.dotnetconsult.co.uk/weblo...d-a68b98b24457
However, I'm not sure about your implementation. Three things:
1. Its a bit heavyweight to allocate a string just for locking
2. Because you use a string literal, anyone else locking the same string literal will be in contention with you as the string is interned
3. If anyone updates the string they will end up with a different object and so you then have a race condition
Its much simpler to use
private static readonly object myGuardObject = new object();
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
No. What this does is cause a lock of any code location that uses the
same lock definition. If every method in the class had its code
encompassed by the same statement it would cause the whole class to lock
anytime one of the methods was entered, but only if that was the case.
If you want to make sure that only the one method is locked you could
create a private static member variable for the specific method, then
lock against that. For example:
private static string _logTextLock = "This is used to lock.";
public static void LogText(string text)
{
lock (_logTextLock)
{
...
}
}
Hope that helps.
Have A Better One!
John M Deal, MCP
Necessity Software