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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:29:23+00:00 2026-05-25T01:29:23+00:00

First of all, I am using Visual Studio 10 and coding Windows Forms App.

  • 0

First of all, I am using Visual Studio 10 and coding Windows Forms App. I am not experienced with threads in C#.

I have a C# app which uses my C# DLL that listens to a Network Stream, and parses the data it receives. The parsed data is used to insert/update the rows of the Datatable which is bound to the DataGridView that is located on the main form.

I have tried this first with a worker thread which is started inside the DLL. The DataTable which is bound to the DataGridView is passed as a parameter to the DLL. And then the thread starts. The thread function was something like this;

private void ListenThread()

    {
        Thread.CurrentThread.CurrentCulture =
            System.Globalization.CultureInfo.InvariantCulture;
        while (m_Active)
        {
            Thread.Sleep(100);
            int lData = m_Stream.Read(m_Buffer, 0,
                  m_Client.ReceiveBufferSize);
            String myString = Encoding.UTF7.GetString(m_Buffer);
            myString = myString.Substring(0, lData);
            ParseString(myString);

        }
    }

The ParseString() method parses the data and inserts a row to the DataTable or updates the existing ones.

This code was working well, until I tried to run the app with CTRL+F5 instead of F5. The UI became unresponsive after a few seconds later it began to fill the Grid.

I have googled this and found that I should use BeginInvoke to prevent the UI from freezing. But I was not successful to implement that.

I tried something like

TCPListener Listener = new TCPListener(ListenThread);
IAsyncResult result = Listener.BeginInvoke(null, null);

instead of

Thread m_tidListen = new Thread(new ThreadStart(ListenThread));

but it worked the same way. Still doesnt work with “without debugging mode”.

How should I implement this with BeginInvoke? Or should I try something else?

  • 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-25T01:29:23+00:00Added an answer on May 25, 2026 at 1:29 am

    Since you are building winforms already, you might as well use a BackGroundWorker for this kind of thing. They are made for doing stuff in the Background while keeping your form responsive. For example:

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //do your time consuming stuff
            while (m_Active)
            {
                Thread.Sleep(100);
                int lData = m_Stream.Read(m_Buffer, 0,
                      m_Client.ReceiveBufferSize);
                String myString = Encoding.UTF7.GetString(m_Buffer);
                e.result = myString.Substring(0, lData);
    
                ParseString(e.Result.ToString());
            }
    
        }
    
     private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //update your UI if needed
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

note: First of all i am using visual studio 2010. Usually i need dll
First, my development environment: Win7 laptop with Visual Studio Professional 2010. IIS is NOT
I have been using Visual Studio 2010 SP1 for C++ in the default setting
I'm using Visual Studio 2005 to script out a database so that I can
I am using Microsoft Visual Studio Professional 2010. (Also SQL Management Studio for my
I am using Visual Studio 2010 SP1 with MVC3 Tools Update, and EF 4.1
I have a visual studio 2010 web project that when I publish it in
I'm using Visual Studio 2010 for recording some web tests. I intend to build
I am using Visual Source Safe 2005 and Visual Studio 2008. @#$% this Source
I've started using Code Contracts in all new code I'm writing, such as 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.