473,462 Members | 1,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to cancel a pending BeginReceive ?

What is the proper way to cancel a pending BeginReceive/EndReceive ?
Can it be done without generating an exception ?

Currently I shutdown and close the socket. The blocking "EndReceive"
throws System.ObjectDisposedException.

I try to avoid throwing exceptions when ever possible, and reserve
them for unanticipated problems. Trying to stop a background
read/process loop is an anticipated activity. For me the debugger
delays 15 seconds when ever an exception is thrown. But regardless, I
am hoping for a cleaner approach. I can not find guidance on this
issue in framework documentation.

Forgive the cross posts. It would be nice to have a specific
framework/network related NG.

Thanks for any insight - Best regards - Lee Gillie - Spokane, WA
Nov 20 '05 #1
1 1990
Ok, experimentation shows this seems to be the trick...

Do a shutdown on the socket.
EndReceive completes with zero bytes
I need to WAIT for this occur before shutdown thread then does a
close, otherwise the exception

"Lee Gillie" <AN*******************@odp.com> wrote in message
news:Os*************@TK2MSFTNGP11.phx.gbl...
What is the proper way to cancel a pending BeginReceive/EndReceive ?
Can it be done without generating an exception ?

Currently I shutdown and close the socket. The blocking "EndReceive" throws System.ObjectDisposedException.

I try to avoid throwing exceptions when ever possible, and reserve
them for unanticipated problems. Trying to stop a background
read/process loop is an anticipated activity. For me the debugger
delays 15 seconds when ever an exception is thrown. But regardless, I am hoping for a cleaner approach. I can not find guidance on this
issue in framework documentation.

Forgive the cross posts. It would be nice to have a specific
framework/network related NG.

Thanks for any insight - Best regards - Lee Gillie - Spokane, WA

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alexander van Meerten | last post by:
Hello, I have to make an application that works on pc and apple mac. Therefore I am investigating if it's possible to use html/javascript. The database has 10000 records and is sequentially...
1
by: Lee Gillie | last post by:
What is the proper way to cancel a pending BeginReceive/EndReceive ? Can it be done without generating an exception ? Currently I shutdown and close the socket. The blocking "EndReceive" throws...
2
by: dream machine | last post by:
Hi all , with BegeinReceive I can build async method of Socket Class that Receive the data from the Socket Client . My question is , if I have this code that create 3 Receive Async Call : ...
0
by: ?lafur Helgi R?gnvaldsson | last post by:
I'm building a server application which accepts socket connections and I ran into some problems. The socket is asynchronous and therefore uses the BeginXXX and EndXXX methods in the Socket class...
3
by: Jacob | last post by:
I'm writing a class that communicates with a server using the TcpClient class. Most of the methods I've written are intended to be used synchronously and will block until they are completed. But...
6
by: Steve Richter | last post by:
I dont get the point of socket.BeginReceive and socket.EndReceive. As I understand it, BeginReceive will start a 2nd thread, call the ReceiveCallback delegate in the 2nd thread, then block until...
4
by: Ryan Liu | last post by:
TcpClient has a method called GetworkStream GetStream(); So in other words, there is only one stream associate with it for input and output, right? So while it is receiving, it can not send, and...
4
by: Anders R | last post by:
Hi, Anyone know howto cancel a pending async operation? I'm using the .NET 2.0 SerialPort and I start a BeginRead(...); What I like to do is to cancel that pending read. In c++ or with api...
2
by: Robinson | last post by:
I can start an Asynchronous operation against a data source with SQLCommand.BeginExecuteReader, allowing me to loop, checking for user cancellation before the operation has completed, but how then...
2
by: O.B. | last post by:
In the following code snippet, the thread successfully makes it to the line where it waits for data to be received. Then the client closes the connection. The thread wakes up and returns from the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.