Correct. .NET utilizes the I/O completion port asynchronous socket model (WSASend/WSARecv) and therefore has the same restrictions as unmanaged code using that model. One of those restrictions is that the thread initiating the socket operation cannot terminate before it is completed or the asynch operation is canceled. This is a behavior of I/O completion ports - not of .NET itself. You should still get the callback, but when EndSend is called, it should throw an exception indicating that the operation was canceled.
If you have scenarios where your own threads might exit with pending I/O events you will either need to ensure they stick around or post the work to a thread pool (ThreadPool.QueueUserWorkItem) and initiate the BeginSend from there. The CLR will ensure that the thread will stick around in that case (it tracks overlapped I/O from the threadpool threads). Best Regards, Mark Smith > -----Original Message----- > From: Unmoderated discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of > Garry Barclay > Sent: Monday, July 26, 2004 2:07 AM > To: [EMAIL PROTECTED] > Subject: Re: [ADVANCED-DOTNET] Missing callbacks from > asynchronous sockets? > > The client calls are made from a ThreadPool thread (initiated > by QueueUserWorkItem). > > Just to be clear - are you saying that a thread which > initiates BeginSend successfully (i.e. no exceptions and > CompletedSynchronously == false) must not terminate until the > EndSend is received? Surely the EndSend will be returned on a > ThreadPool (completion) thread? > > >Any chance the thread that initiated the BeginSend is ending > before the > >callback is received? This can happen if you're using a home-grown > >thread pool. The system ThreadPool has special logic to ensure a > >thread is never destroyed if there are pending IOCP requests. > > > >Rick > > > >-----Original Message----- > >From: Unmoderated discussion of advanced .NET topics. > >[mailto:[EMAIL PROTECTED] On Behalf Of > Garry Barclay > >Sent: Wednesday, July 21, 2004 5:10 AM > >To: [EMAIL PROTECTED] > >Subject: [ADVANCED-DOTNET] Missing callbacks from > asynchronous sockets? > > > >It appears that we are NOT receiving the (completion port) callback > >from an asynchronous socket (BeginSend/EndSend) call. > > > >The sockets are clients and the failure seems to be related to > >shutdowns on the socket. > > > >This has the effect of leaving a pinned GCHandle on the heap > (pinning > >the send buffer). We've checked the process memory dump with > WinDbg and > >have seen that the sockets are shutdown successfully. Checking the > >Socket class implementation (v1.1) with Reflector it's seems > clear that > >IF the callback is made then the buffer should always be unpinned. > > > >We've added in static counters using interlocked.xxx to > verify that the > >calls are definitely not reaching our code, and this confirms our > >suspicions. > > > >Because of the pinned buffers, heap compaction can't take > place and we > >end up with high memory usage figures even though most of > the heap is > >free space between those buffers. > > > >Anyone seen something like this before? > > > >=================================== > >This list is hosted by DevelopMentor(r) http://www.develop.com Some > >.NET courses you may be interested in: > > > >NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles > >http://www.develop.com/courses/gaspdotnetls > > > >View archives and manage your subscription(s) at > >http://discuss.develop.com > > > >=================================== > >This list is hosted by DevelopMentorR > http://www.develop.com Some .NET > >courses you may be interested in: > > > >NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles > >http://www.develop.com/courses/gaspdotnetls > > > >View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentorR http://www.develop.com > Some .NET courses you may be interested in: > > NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles > http://www.develop.com/courses/gaspdotnetls > > View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com