Article View: borland.public.csharpbuilder.language.csharp
Article #246threading issue with socket and arraylist
From: Francois Piette [ICS & Midware]
Date: Wed, 02 Aug 2006 08:09
Date: Wed, 02 Aug 2006 08:09
21 lines
1924 bytes
1924 bytes
I'm writing a program which make use of asynchronous sockets. My program call Socket.BeginAccept() to make the .NET framework create a thread for me and make it wait for an incomming connection while my program continue to run normally. When a new connection comes in, my callback method (specified by BeginAccept) is invoked in the context of the worker thread managed by .NET. I call EndAccept to get the client connection. So far so good. When I have a client connection, I place it into a variable Clients of type ArrayList. That's where I have a problem: The variable Clients is accessed from the accept callback within the context of a worker thread and it is also accessed by the main thread. How do I manage thread synchronization ? Do I have to use a critical section or some C# equivalent contruction ? Any help appreciated. Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- francois.piette@overbyte.be Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be
Technical Details
Message-ID:
<44d05d46$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,fffd9ba0a592c265,start X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Francois Piette [ICS & Midware]" <francois.piette@overbyte.be> Newsgroups: borland.public.csharpbuilder.language.csharp Subject: threading issue with socket and arraylist Date: Wed, 2 Aug 2006 10:09:56 +0200 Lines: 23 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 NNTP-Posting-Host: 62.197.126.228 Message-ID: <44d05d46$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1154506054 62.197.126.228 (2 Aug 2006 01:07:34 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail