Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 542183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:25:12+00:00 2026-05-13T10:25:12+00:00

I am making an server/client application. I set server socket to listening, and set

  • 0

I am 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 did search on the net and found this is not an error but a designed exception as beginaccept was cancelled.

my question how do i handle this excepton? what processing there needs to be for it?

I’m just going to treat it as a normal event:

      OnNetworkEvents eventArgs = new OnNetworkEvents(false, "Ready", e.Message);
      OnUpdateNetworkStatusMessage(this, eventArgs);

any comments are still welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:25:13+00:00Added an answer on May 13, 2026 at 10:25 am

    If you don’t care about the exception (i.e. it’s not an “exception”, it’s the normal operating procedure and happens every time), you can just ignore/suppress it. (Just as long as it won’t happen in a situation that indicates a real error)

    If you want to suppress it more tidily, then you can set a flag that tells your callback that it should shut down, and have the callback actually do the closing/disposing of the socket. That way you can guarantee that there are no pending reads on the socket and won’t get the exception (but this means it will hang about indefinitely, until another packet is received – which of course may never happen).

    If you are in control of both ends of the communications link, then you can send an explicit “shutdown” message that tells the client that the connection should be closed (and this can of course be applied in the callback when the message is received).

    (But I’d love to hear if anyone else has found a better solution as I have a similar situation with a UDP comms implementation)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My understanding of your question is that you want to… May 14, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer If you are looking for add ons to the Java… May 14, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer hover changed in 1.4 and funny no one here seems… May 14, 2026 at 8:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.