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 6137805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:46:21+00:00 2026-05-23T17:46:21+00:00

I have a fairly generic C# socket server that uses the asynchronous methods of

  • 0

I have a fairly generic C# socket server that uses the asynchronous methods of the socket classes – BeginAccept(), BeginReceive(), etc. This server has been working great for the last 4 years at many customer sites running Win Server 2003. Recently I installed it on a Windows Server 2008 R2 server, 64-bit. Everything looks fine until the first client connects and issues a BeginReceive() and a BeginAccept() call in the accept handler. When this happens, the CPU usage spikes to 100% and stays that way until I close the listening socket.

Not sure that it matters, but the server is running in a virtual machine.

Have done a lot of testing, but nothing seems to help. Using Process Explorer, I can see that two threads are spun up shortly after the BeginReceive()/BeginAccept() calls, and they are the ones that are consuming the processor. Unfortunately, I am not able to reproduce this problem on my Win7 64-bit workstation.

I have done a lot of research, and all that I have found so far is the following two KB articles that imply that Server 2008 R2 may have an issue with the TCP/IP components, but they are only available as hot fixes: KB2465772 and KB2477730. Am reluctant to have my customer install them until I am more certain that they will fix the issue.

Has anyone else had this problem? If so, what did you have to do to resolve this issue?

Here is the method that I believe causes the situation:

private void AcceptCallback(IAsyncResult result) {
 ConnectionInfo connection = new ConnectionInfo();

 try {
    // Finish accept.
    Socket listener = (Socket)result.AsyncState;
    connection.Socket = listener.EndAccept(result);
    connection.Request = new StringBuilder(256);

    // Start receive and a new accept.
    connection.Socket.BeginReceive(connection.Buffer, 0,
       connection.Buffer.Length, SocketFlags.None,
       new AsyncCallback(ReceiveCallback), connection);

    _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), listener);

    // CPU usage spikes at 100% shortly after this...

 }
 catch (ObjectDisposedException /*ode*/) {
    _log.Debug("[AcceptCallback] ObjectDisposedException");
 }
 catch (SocketException se) {
    connection.Socket.Close();
    _log.ErrorFormat("[AcceptCallback] Socket Exception ({0}: {1} {2}", connection.ClientAddress, se.ErrorCode, se.Message);
 }
 catch (Exception ex) {
    connection.Socket.Close();
    _log.ErrorFormat("[AcceptCallback] Exception {0}: {1}", connection.ClientAddress, ex.Message);
 }
}
  • 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-23T17:46:22+00:00Added an answer on May 23, 2026 at 5:46 pm

    The issue was caused by having more than one call to BeginAccept() when setting up the listener socket. Do not know why the problem only occurs on 64bit servers, but changing the code as shown below fixed the issue.

    Original code:

    public SetupServerSocket() {
       IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, _port);
    
       // Create the socket, bind it, and start listening.
      _serverSocket = new Socket(myEndPoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
      _serverSocket.Bind(myEndPoint);
      _serverSocket.Listen((int)SocketOptionName.MaxConnections);
    
      for (int i = 0; i < 10; i++) {
         _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), _serverSocket);
      }
    }
    

    To the following:

    public SetupServerSocket() {
       IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, _port);
    
       // Create the socket, bind it, and start listening.
      _serverSocket = new Socket(myEndPoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
      _serverSocket.Bind(myEndPoint);
      _serverSocket.Listen((int)SocketOptionName.MaxConnections);
    
      //for (int i = 0; i < 10; i++) {
         _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), _serverSocket);
      //}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have a fairly generic table (Data), that has an identity column. The
I have a fairly small MySQL database (a Textpattern install) on a server that
I have some fairly generic code which uses preprocessor macros to add a certain
I have a fairly generic class (Record) that I have added a callback handler
This is a fairly generic question in that I'm just wondering what potential options
I have a fairly large work project that uses pygtk for the GUI and
I have a fairly simple expression parser that uses the Linq.Expression namespace. Input is
I have a fairly complex multi threaded application (server) that from time to time
I have a fairly standards compliant XHTML+CSS site that looks great on all browsers
I have a fairly large codebase that depends on MooTools v1.11 and am about

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.