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

  • Home
  • SEARCH
  • 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 8894989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:39:13+00:00 2026-06-14T23:39:13+00:00

When I want to open a new Thread for every Incoming Request. Is this

  • 0

When I want to open a new Thread for every Incoming Request. Is this good way to do it? Will there be a new Thread with every accepted Request? The BeginReceive Method called in the end of this piece of code Works asynchronous aswell.

public void Listen(IPEndPoint EndPoint)
    {
        try
        {
            ListeningSocket.Bind(EndPoint);
            ListeningSocket.Listen(BACKLOG);
            BeginAccept();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message + "\nfrom Source: " + e.Source + "\nand Stack Trace: " + e.StackTrace);
        }
    }

    public void BeginAccept()
    {
        try
        {
            ListeningSocket.BeginAccept(new AsyncCallback(Accept_Callback), new ServerSocket());
        }
        catch (SocketException e)
        {
            Console.WriteLine("Listening Socket Error:" + e.ErrorCode);
        }
        catch (ObjectDisposedException e)
        {
            Console.WriteLine("The Listening Socket has been closed");
        }
    }


    private void Accept_Callback(IAsyncResult asyncResult)
    {
        BeginAccept();
        try
        {
            if (asyncResult.AsyncState != null)
            {
                ServerSocket serverSocket = asyncResult.AsyncState as ServerSocket;
                if ((serverSocket.CommunicationSocket = ListeningSocket.EndAccept(asyncResult)) != null)
                {

                    BeginReceive(serverSocket);
                }
            }
        }
        catch (SocketException e)
        {
            Console.WriteLine("Listening Socket Error:" + e.ErrorCode);
        }
        catch (ObjectDisposedException e)
        {
            Console.WriteLine("The Listening Socket has been closed");
        }
    }
  • 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-06-14T23:39:14+00:00Added an answer on June 14, 2026 at 11:39 pm

    This approach uses threads from a ThreadPool which is a good thing. While waiting for a new client to be accepted or for data to arrive no threads are used, so your code will not span 1000 threads when you have 1000 clients connected.

    Just when data arrives on one socket, one free thread will be taken from the tread pool and will process your callback. When your method finishes, the thread will be returned to the pool to be available for the next data arrival or client connection.

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

Sidebar

Related Questions

Say, I want to open up a new thread each time a button is
from this thread thread i can open new window by using message this comment
I'm new to VSDO, and i want to open new template/word popup window within
I want to be able to click a button and open a new form
I have a button: <button>Click</button> I want click it and open a new window
I want to open a document file using Open Xml Open Method, search for
I am creating a Kinect application and want to open a new window called
The goal of this code is to run four threads, which will open four
I want to open up a new view with the identifier AddSourceViewController when a
I have this Java Swing application that starts a new thread that uses a

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.