Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
GeneralRe: load data's from a xml file into a dataset for a single field alone Pin
dhol31-Dec-04 16:58
dhol31-Dec-04 16:58 
GeneralAdding dll to the workspace Pin
Md Saleem Navalur30-Dec-04 23:21
Md Saleem Navalur30-Dec-04 23:21 
GeneralRe: Adding dll to the workspace Pin
Heath Stewart31-Dec-04 6:38
protectorHeath Stewart31-Dec-04 6:38 
GeneralRe: Adding dll to the workspace Pin
Md Saleem Navalur31-Dec-04 21:29
Md Saleem Navalur31-Dec-04 21:29 
GeneralRe: Adding dll to the workspace Pin
Heath Stewart31-Dec-04 22:49
protectorHeath Stewart31-Dec-04 22:49 
Questionhow to lock a method in class Pin
ting66830-Dec-04 22:11
ting66830-Dec-04 22:11 
AnswerRe: how to lock a method in class Pin
Robert Rohde30-Dec-04 22:19
Robert Rohde30-Dec-04 22:19 
AnswerRe: how to lock a method in class Pin
Heath Stewart31-Dec-04 6:26
protectorHeath Stewart31-Dec-04 6:26 
ting668 wrote:
But by using lock(this) to the
method will cause the whole object to be locked,


That's not true. The object is not locked in such a way that nothing else can use it. Unless a method also calls lock(this) or otherwise locks whatever object this refers to, the method can run in a separate thread (not in the current thread, of course, since you're already executing a method).

What Robert said is good, though. If you want to synchronize each method individually then create separate static instances of objects to lock against. These must be static so that they are the same object for all instances of your object in any thread within a single AppDomain.

If you're going to synchronize each method individually and don't need instance data, I recommend you make the methods static. The CLR will synchronize static methods allowing only one thread of execution to enter at a time within a given AppDomain. This would be the same as locking against separate objects for each method yourself and makes for a better design and uses less memory (additional objects are not necessary).

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: how to lock a method in class Pin
ting6682-Jan-05 15:13
ting6682-Jan-05 15:13 
GeneralRe: how to lock a method in class Pin
Heath Stewart2-Jan-05 21:18
protectorHeath Stewart2-Jan-05 21:18 
GeneralRe: how to lock a method in class Pin
ting6683-Jan-05 14:49
ting6683-Jan-05 14:49 
GeneralRe: how to lock a method in class Pin
Heath Stewart3-Jan-05 18:47
protectorHeath Stewart3-Jan-05 18:47 
QuestionIs this kind of encapsulation right for the event and delegate? Pin
Salil Khedkar30-Dec-04 20:00
Salil Khedkar30-Dec-04 20:00 
AnswerRe: Is this kind of encapsulation right for the event and delegate? Pin
Heath Stewart30-Dec-04 20:29
protectorHeath Stewart30-Dec-04 20:29 
GeneralRe: Is this kind of encapsulation right for the event and delegate? Pin
Salil Khedkar2-Jan-05 21:26
Salil Khedkar2-Jan-05 21:26 
Generalload values into the dataset form the xml Pin
dhol30-Dec-04 19:11
dhol30-Dec-04 19:11 
GeneralProgrammetically Selection of Language Pin
SoloVision30-Dec-04 18:22
SoloVision30-Dec-04 18:22 
GeneralRe: Programmetically Selection of Language Pin
Heath Stewart30-Dec-04 20:14
protectorHeath Stewart30-Dec-04 20:14 
Generalprogramticly scroll a richtextbox Pin
Tyrus18230-Dec-04 14:46
Tyrus18230-Dec-04 14:46 
GeneralRe: programticly scroll a richtextbox Pin
Heath Stewart30-Dec-04 20:06
protectorHeath Stewart30-Dec-04 20:06 
Generalusing non true type or open type fonts Pin
Tyrus18230-Dec-04 14:43
Tyrus18230-Dec-04 14:43 
Questionwhat is wrong here ? Pin
kings_130-Dec-04 11:38
kings_130-Dec-04 11:38 
AnswerRe: what is wrong here ? Pin
Heath Stewart30-Dec-04 12:06
protectorHeath Stewart30-Dec-04 12:06 
GeneralRe: what is wrong here ? Pin
kings_130-Dec-04 19:46
kings_130-Dec-04 19:46 
GeneralRe: what is wrong here ? Pin
Heath Stewart30-Dec-04 20:01
protectorHeath Stewart30-Dec-04 20:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.