Exception when canceling socket listening.

F

FU.U.NA

Hi.
I found some strange working from .NET Socket class.
I couldn't solve this problem myself.
Please help me.

I was making an server/client application.
I set server socket to listening, and set BeginAccept() method.
And when I closed server socket (Socket.Close()) to turn off server,
an exception thrown from BeginAccept() method's async callback method.
I inspected exception, and I found the exception saying me this:

Message "Cannot access a disposed object named
"System.Net.Sockets.Socket".
Object name: "System.Net.Sockets.Socket"." String

In my opinion, this is just this: "The socket disposed when I call
Socket.Close() method, but the callback did not released before the
socket closed."

I think there must be an option to tweak this operation.
But I can't know what the option is.

And there is no option to tweak this, this is some buggy action. MS
people need to documentation this.

However, anybody knows how to solve this, please help me.
Thnks for reading.
 
F

Feroze [MSFT]

This is by design. You are disposing of the socket while it is in use ( i.e
a BeginAccept() is outstanding). You should handle this in your application.

--
Remove "user" from the email address to reply to the author.

This posting is provided "AS IS" with no warranties, and confers no rights

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top