Click here to Skip to main content
15,890,336 members
Home / Discussions / C#
   

C#

 
QuestionDataGridView and Animated gif Problem! Pin
mertkan6526-Apr-07 0:45
mertkan6526-Apr-07 0:45 
QuestionDifference between SyncRoot property and Synchronized method? Pin
kumar.bs26-Apr-07 0:12
kumar.bs26-Apr-07 0:12 
AnswerRe: Difference between SyncRoot property and Synchronized method? Pin
Sathesh Sakthivel26-Apr-07 0:21
Sathesh Sakthivel26-Apr-07 0:21 
GeneralRe: Difference between SyncRoot property and Synchronized method? Pin
kumar.bs26-Apr-07 0:32
kumar.bs26-Apr-07 0:32 
GeneralRe: Difference between SyncRoot property and Synchronized method? Pin
Sathesh Sakthivel26-Apr-07 0:35
Sathesh Sakthivel26-Apr-07 0:35 
AnswerRe: Difference between SyncRoot property and Synchronized method? Pin
peterchen26-Apr-07 6:41
peterchen26-Apr-07 6:41 
GeneralRe: Difference between SyncRoot property and Synchronized method? Pin
kumar.bs26-Apr-07 18:33
kumar.bs26-Apr-07 18:33 
GeneralRe: Difference between SyncRoot property and Synchronized method? Pin
peterchen27-Apr-07 3:20
peterchen27-Apr-07 3:20 
kumar.bs wrote:
if we synchronize the whole method, how other thread can make calls between Count and RemoveAt?

They can't (as long as they use the lock), and that's the whole point. because between "Count" and "RemoveAt" noone may modify the list.

Keep in mind that querying Count is usually very fast, so lock acquisition and RemoveAt will take the majority of execution time anyway.


kumar.bs wrote:
lock(mylist.syncRoot) can't we specify lock(mylist)?


Two problems:
First, "List Proxies". The synchronization works correct only if all threads accessing the list use the same object to lock on. However, the List interface might not hold the data itself, but expose the interface for some underlying data. If one thread lokcs on the list proxy, and another thread locks on the underlying data, we have the concurrent access we need to avoid.

Second, Lock Order.
There is a problem wiht locking on publicly visible symbols. When you have two locking objects A and B, one thread might lock in the order A, B the other in order B,A. This leads to a deadlock situation that cannot be solved.

That's why locking on public objects is almost always a bad idea. You need to be very clear which lock objects exsit in your code (and the code you call!), and give them a definite order. SyncRoot helps here a little bit since it is a dedicated object used for locking, that is provided by the underlying data.


helped? Smile | :)



We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
My first real C# project | Linkify!|FoldWithUs! | sighist

GeneralRe: Difference between SyncRoot property and Synchronized method? Pin
kumar.bs29-Apr-07 21:05
kumar.bs29-Apr-07 21:05 
QuestionUrgent: How to refresh the status bar during a process Pin
dudedotnet26-Apr-07 0:09
dudedotnet26-Apr-07 0:09 
AnswerRe: Urgent: How to refresh the status bar during a process Pin
Christian Graus26-Apr-07 0:25
protectorChristian Graus26-Apr-07 0:25 
GeneralRe: Urgent: How to refresh the status bar during a process Pin
dudedotnet26-Apr-07 0:31
dudedotnet26-Apr-07 0:31 
GeneralRe: Urgent: How to refresh the status bar during a process Pin
Christian Graus26-Apr-07 0:39
protectorChristian Graus26-Apr-07 0:39 
Questionvalidation (double) Pin
Keshav V. Kamat25-Apr-07 23:42
Keshav V. Kamat25-Apr-07 23:42 
AnswerRe: validation (double) Pin
Pete O'Hanlon26-Apr-07 0:12
mvePete O'Hanlon26-Apr-07 0:12 
Questionupload file Pin
nilima Dash25-Apr-07 23:29
nilima Dash25-Apr-07 23:29 
AnswerRe: upload file Pin
Christian Graus26-Apr-07 0:21
protectorChristian Graus26-Apr-07 0:21 
AnswerRe: upload file Pin
marky77726-Apr-07 1:42
marky77726-Apr-07 1:42 
QuestionHow to use Math Equation [of Word] in my software? Pin
Majid_grok25-Apr-07 23:14
Majid_grok25-Apr-07 23:14 
AnswerRe: How to use Math Equation [of Word] in my software? Pin
Aaron VanWieren26-Apr-07 5:19
Aaron VanWieren26-Apr-07 5:19 
Question.net Pin
nilima Dash25-Apr-07 23:13
nilima Dash25-Apr-07 23:13 
AnswerRe: .net Pin
Christian Graus25-Apr-07 23:25
protectorChristian Graus25-Apr-07 23:25 
AnswerRe: .net Pin
Keshav V. Kamat25-Apr-07 23:46
Keshav V. Kamat25-Apr-07 23:46 
GeneralRe: .net Pin
Christian Graus26-Apr-07 0:20
protectorChristian Graus26-Apr-07 0:20 
Questionerror in xml validation with xsd(schema) Pin
praveenkumar palla25-Apr-07 22:53
praveenkumar palla25-Apr-07 22:53 

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.