Re: Thread Locking In Static Methods - How?
From: John M Deal (johndeal_at_necessitysoftware.com)
Date: 11/15/04
- Next message: Tamir Khason: "Kind of table"
- Previous message: Dde: "Datacolumn expression IN operator"
- In reply to: McFly Racing: "Re: Thread Locking In Static Methods - How?"
- Next in thread: Richard Blewett [DevelopMentor]: "Re: Thread Locking In Static Methods - How?"
- Reply: Richard Blewett [DevelopMentor]: "Re: Thread Locking In Static Methods - How?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 15 Nov 2004 07:47:34 -0800
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
McFly Racing wrote:
> If I do it this way it seems like I will be loking the whole class instead
> of just this method, is that correct? Thank you.
>
> "ShaneB" <stormfire1@yahoo.com> wrote in message
> news:OR$PReyyEHA.1564@TK2MSFTNGP09.phx.gbl...
>
>>public static void LogText(string text)
>>{
>> lock (typeof(ThisClassType))
>> {
>> ...
>> }
>>}
>>
>>ShaneB
>>
>>"McFly Racing" <NoSpam@Microsoft.com> wrote in message
>>news:ed2F8XyyEHA.2568@TK2MSFTNGP10.phx.gbl...
>>
>>>Thread Locking In Static Methods
>>>
>>>
>>>
>>>I have the need for a Log Manger class that has static methods.
>
> Normally
>
>>>I
>>>would use the lock statement or a Monitor statement both of which take a
>>>reference to (this). In the case of these static methods I am not able
>
> to
>
>>>do that.
>>>
>>>
>>>
>>>How should I perform thread locking within static methods like this?
>>>Thank
>>>you.
>>>
>>>
>>
>>
>
>
- Next message: Tamir Khason: "Kind of table"
- Previous message: Dde: "Datacolumn expression IN operator"
- In reply to: McFly Racing: "Re: Thread Locking In Static Methods - How?"
- Next in thread: Richard Blewett [DevelopMentor]: "Re: Thread Locking In Static Methods - How?"
- Reply: Richard Blewett [DevelopMentor]: "Re: Thread Locking In Static Methods - How?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|