A
Armin Zingler
Hi,
surprisingly, I didn't find any satisfying answer to the following question:
Situation:
I use the TCPListener's BeginAcceptTcpClient method. In the callback
procedure I call EndAcceptTcpClient. To stop listening, the listener's stop
method is to be called.
PRB:
If I call Stop, the callback procedure is called even though no connection
has been made. This leads to an ObjectDisposedException when calling
EndAcceptTcpClient.
Questions:
- Why is the callback called at all? There is no incoming connection.
- What is the correct way to handle the problem? Am I to call
EndAcceptTcpClient in any case and catch the ObjectDisposedException? Or
should I better query listener.Pending and call EndAcceptTcpClient only if
it returns True? If it is False, what happens due to the missing call to
EndAcceptTcpClient? I thought Begin* and End* are to be used in pairs.
- I actually don't want to "End" listening, so why call End* even though I
want to keep on accepting more clients?
- The FW's async model is not very comprehensive. Why is there not a simple
Event from the listener (maybe in another thread)?
Armin
surprisingly, I didn't find any satisfying answer to the following question:
Situation:
I use the TCPListener's BeginAcceptTcpClient method. In the callback
procedure I call EndAcceptTcpClient. To stop listening, the listener's stop
method is to be called.
PRB:
If I call Stop, the callback procedure is called even though no connection
has been made. This leads to an ObjectDisposedException when calling
EndAcceptTcpClient.
Questions:
- Why is the callback called at all? There is no incoming connection.
- What is the correct way to handle the problem? Am I to call
EndAcceptTcpClient in any case and catch the ObjectDisposedException? Or
should I better query listener.Pending and call EndAcceptTcpClient only if
it returns True? If it is False, what happens due to the missing call to
EndAcceptTcpClient? I thought Begin* and End* are to be used in pairs.
- I actually don't want to "End" listening, so why call End* even though I
want to keep on accepting more clients?
- The FW's async model is not very comprehensive. Why is there not a simple
Event from the listener (maybe in another thread)?
Armin