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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:23:45+00:00 2026-05-26T12:23:45+00:00

and greetings to all members. I’m working on a small embedded data acquisition hardware

  • 0

and greetings to all members. I’m working on a small embedded data acquisition hardware which collects data periodically and runs a small embedded webserver. If requested the server replies with a very basic html page along with the collected data in 128 bytes TCP chunks. The size of the transferred data is maximum 64K.

The embedded TCP/IP stack is quite thin and the MCU is not the fastest, so I’d like the requester application to have a progress indicator (a progress bar or similar). Since the length of data array to be transferred is constantly changing the server should insert the actual data length in the beginning of the data array. The requester app should read this length information and update the progress of the progressbar. With the following code I can receive the server content but only can access the data when the transfer is completed:

        TcpClient msnTcpConn = new TcpClient();
        try
        {
            msnTcpConn.Connect(HostName, 80);

            if (msnTcpConn.Connected)
            {

                string msg = "";

                NetworkStream netStream = msnTcpConn.GetStream();
                System.IO.StreamWriter sw = new System.IO.StreamWriter(netStream);
                System.IO.StreamReader sr = new System.IO.StreamReader(netStream);

                string req = "";
                req += "GET / HTTP/1.0\r\n";
                req += "Host: " + HostName + "\r\n";
                req += "\r\n";

                sw.Write(req);
                sw.Flush();
                numa = 0;
                peek = 0;
                while (sr.Peek()>=0)
                {
                    peek = sr.Peek();
                    numa++;
                    textBox1.Text = Convert.ToString(numa);
                    msg += sr.ReadLine();;
                }                 

                webBrowser1.DocumentText = msg;
                msnTcpConn.Close();
            }
            else
            {
                MessageBox.Show("Not connected.");
            }
        }
        catch (UriFormatException UriExc)
        {
            MessageBox.Show("Error!");
        }  

In the above code, textBox1 is not getting refreshed in the while loop only when the loop is exited. Thus, I can’t check the received data in time to extract the data size which is needed to update the progress indicator. I’m a beginner in .NET networking so maybe there is a better way to do this thing so any tip or help would be greatly appreciated. Thank you.

  • 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-26T12:23:46+00:00Added an answer on May 26, 2026 at 12:23 pm

    This is a threading issue. The UI will not update until the code executed on the UI thread is complete. You will want to move your code that reads from the NetworkStream to another thread. You will need to make sure your code that writes to your TextBox does so on the UI thread. You can do this with BeginInvoke if this is a WinForms app.

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

Sidebar

Related Questions

Greetings all, I'm trying to implement middleware (driver) for an embedded device with generic
Greetings all, I'm working with a C# solution in VS 2010. Right now, since
Greetings all, As seen in the picture I have an extended QWidget object (which
Greetings all, I’m working on a C# program that requires being able to get
Greetings All; I have a LinkedList of type String which contain some words like
Greetings all Currently working on assessing a project, and wondered if there was a
Greetings all, I load set of images and generate volume data.I save this volume
greetings all i have an application which are made with Spring framework and deployed
greetings all I have a post method in a controller, which redirects to a
Greetings All; I have a desktop java application which gives the following output in

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.