Click here to Skip to main content
16,004,882 members
Home / Discussions / C#
   

C#

 
GeneralRe: Hot to detect a mouse hit on an image Pin
vikas amin8-Aug-08 4:43
vikas amin8-Aug-08 4:43 
GeneralRe: Hot to detect a mouse hit on an image Pin
vikas amin4-Aug-08 4:57
vikas amin4-Aug-08 4:57 
GeneralRe: Hot to detect a mouse hit on an image Pin
NeutronMass4-Aug-08 5:35
NeutronMass4-Aug-08 5:35 
GeneralRe: Hot to detect a mouse hit on an image Pin
vikas amin12-Aug-08 11:50
vikas amin12-Aug-08 11:50 
QuestionVista C# developer basics Pin
Stevo Z4-Aug-08 3:15
Stevo Z4-Aug-08 3:15 
AnswerRe: Vista C# developer basics Pin
John Ad4-Aug-08 4:54
John Ad4-Aug-08 4:54 
GeneralRe: Vista C# developer basics Pin
Stevo Z4-Aug-08 5:11
Stevo Z4-Aug-08 5:11 
Questionexplicit interface implementation of ICollection in Generic Classes Pin
MarkPhB4-Aug-08 3:06
MarkPhB4-Aug-08 3:06 
Hi, Smile | :)

I have a generally question that bother me.

Let me explain it with an example, so that you understand the question.

Let's say we have simple TcpSerer-class which a ConnectionList and looks like this
public class TcpServer {

        public List<tcpclient> ConnectionList { get; }

        public void start () { }

        public void stop () { }

        private void client_Connected ( TcpClient client ) {
            ConnectionList.Add( client );
        }

        private void client_Disconnected ( TcpClient client ) {
            ConnectionList.Remove( client );
        }
    }</tcpclient>
So, as you can see, this class is not thread-safe.

Because an exception will thrown when i enumerate the ConnectionList
while some Client connect or disconnect.

Thats why i need an object to provide a possibility to lock the ConnectionList
while i enumerate it. OK so far so good. Smile | :)

Now i thought just take the SyncRoot-Property from the ICollection Interface implementation.

But someone told me, i should not use that Object for synchronization with the list.

Because the SyncRoot-Property was a mistake from Microsoft and decoy the developers
to use it without thinking about synchronization. Sniff | :^)

But the same one told me, that there is no differenc between the object from the SyncRoot-Property
and the object i could provide with a derivation of the List<T>. D'Oh! | :doh:

Thats why my questions:

Q#1 - Is it true that the SyncRoot-Property was a mistake from Microsoft and shoundnt be used for synchronization. ? Confused | :confused:

Q#2 - If Q#1 is true then - Why ? Confused | :confused:

Q#3 - What its the recommended pattern to lock / synchronize any collection.Confused | :confused:

Thanks in advance.

P.S.: I asked this question already in the msdn-forum but it doesn't satisfy me.
Link: http://forums.msdn.microsoft.com/en-US/netfxbcl/thread/3d760576-7cd2-44d5-936e-969ff5213648/[^]
AnswerRe: explicit interface implementation of ICollection in Generic Classes Pin
Simon P Stevens4-Aug-08 3:30
Simon P Stevens4-Aug-08 3:30 
GeneralRe: explicit interface implementation of ICollection in Generic Classes Pin
MarkPhB4-Aug-08 3:57
MarkPhB4-Aug-08 3:57 
GeneralRe: explicit interface implementation of ICollection in Generic Classes Pin
Simon P Stevens4-Aug-08 10:58
Simon P Stevens4-Aug-08 10:58 
GeneralRe: explicit interface implementation of ICollection in Generic Classes Pin
MarkPhB4-Aug-08 19:37
MarkPhB4-Aug-08 19:37 
GeneralRe: explicit interface implementation of ICollection in Generic Classes Pin
Simon P Stevens4-Aug-08 23:27
Simon P Stevens4-Aug-08 23:27 
QuestionProblem in excel, Please help................................................................................... Pin
Mogaambo4-Aug-08 3:06
Mogaambo4-Aug-08 3:06 
AnswerRe: Problem in excel, Please help................................................................................... [modified] Pin
Thomas Stockwell4-Aug-08 3:53
professionalThomas Stockwell4-Aug-08 3:53 
QuestionI want to open PDF File in my application Pin
Laji594-Aug-08 2:27
Laji594-Aug-08 2:27 
AnswerRe: I want to open PDF File in my application Pin
Pete O'Hanlon4-Aug-08 2:55
mvePete O'Hanlon4-Aug-08 2:55 
GeneralRe: I want to open PDF File in my application Pin
Laji594-Aug-08 3:22
Laji594-Aug-08 3:22 
GeneralRe: I want to open PDF File in my application Pin
Pete O'Hanlon4-Aug-08 4:07
mvePete O'Hanlon4-Aug-08 4:07 
GeneralReposter... Pin
Paul Conrad4-Aug-08 5:53
professionalPaul Conrad4-Aug-08 5:53 
GeneralRe: I want to open PDF File in my application Pin
Thomas Stockwell4-Aug-08 4:08
professionalThomas Stockwell4-Aug-08 4:08 
AnswerRe: I want to open PDF File in my application Pin
Gulfraz Khan4-Aug-08 4:23
Gulfraz Khan4-Aug-08 4:23 
GeneralRe: I want to open PDF File in my application Pin
Laji594-Aug-08 18:35
Laji594-Aug-08 18:35 
Questioncapturing events at form level Pin
neer14-Aug-08 2:15
neer14-Aug-08 2:15 
AnswerRe: capturing events at form level Pin
Simon P Stevens4-Aug-08 2:21
Simon P Stevens4-Aug-08 2:21 

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.