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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:21:11+00:00 2026-05-20T22:21:11+00:00

I’m developing an application that is running a lot of TcpListener tasks using c#

  • 0

I’m developing an application that is running a lot of TcpListener tasks
using c# with .net 3.5 on windows server 2008

the TcpListener task is:

  1. listening
    to get an xml message
  2. read an ID
    from it
  3. send a command to a
    specific camera based on the ID to
    take a snapshot and store it in a
    folder

This is meant to execute within 1 second so I can take a snapshot with the camera. I’ve got a delay in executing this task, using the following code:

private Thread listen_thread;

    public void start_listen()
    {
            this.listen_thread = new Thread(new ThreadStart(save_data));
            this.listen_thread.Priority = ThreadPriority.Normal;
            this.listen_thread.Start();

    }
    private void save_data()
    {
        //work to be done
    }

Is this the best multi-threading technique to use? This application is running on a on dell poweredge 2900
with 2 quad core prosessor, and I think it could go faster. How might I be able to improve the latency of this code?

thats the code for the tcplistener

Int32 port = controller_port;
        try
        {
            //this server ip
            IPAddress localAddr = IPAddress.Parse(this_ip);
            server = new TcpListener(localAddr, port);
            server.Start();
            Byte[] bytes = new Byte[256];
            String data = null;
            while (true)
            {
                Console.Write("Waiting for a connection... ");
                TcpClient client = server.AcceptTcpClient();
                Console.Write("Connected!");
                data = null;
                NetworkStream stream = client.GetStream();
                int i;
                string add_data = "";
                Console.Write("Waiting...!");
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    try
                    {
                        string full_row = "";
                        data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                        Console.Write("Received from controller: " + data);
                        add_data += data;
                    }
                    catch{}
                }
            }
         }

then i divide it to get the ID .

  • 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-20T22:21:12+00:00Added an answer on May 20, 2026 at 10:21 pm

    It’s not clear at all

    1. how you receive requests
    2. upon what you parallelize the application

    It seems that you listen on different sockets and assign a thread on each of them.

    I think this is a poor choice, because you can’t control the parallelism degree.

    You could instead have just one thread that nondeterministically listens on all sockets and assigns the connection to a thread pool, configured to simultaneously run at most n threads, where n is the parallelism degree of your machine (if you have a dual quadcore, n is equal to 8).

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

Sidebar

Related Questions

No related questions found

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.