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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:57:06+00:00 2026-05-12T10:57:06+00:00

I working on project and have problem with threading and update of UI. I

  • 0

I working on project and have problem with threading and update of UI. I read many post around web and this site, but didnt find answer to my problem.

I making program that a waiting for some UDP data on port XXXX. Looping in separated thread. When data come he extract information and put it in buffer, and go back wait another data. Another thread routine wait for data in buffer and send it to email.

Because of functionality and code design I have Form1 class (UI) – main thread, Class2 (rutine for reading UDP and extracting data ) – secodn thread, Class3( reading buffer and send mail ) – third thread, Class4 ( Queue buffer ( read, write, delete items ))…

Problem is that when I want to update UI from one of Class I got BufferOwerflow Exception…It’s logical because I first must make instance if Class to start threading and in Class I must make instance of Form to pass data, and then we have infinite loop.

All post I found here are about update UI from thread but in same Class. I understand problem about stack and looping because of instances. I just don’t want to have one big main class with huge amount of code inside…

Is it posible to update main Form form another class and threading routine inside?

I write some example from head ( it’s not working ) just to have clue about what I am talking.

namespace ThreadUIClass
{
    public delegate void updateTextBoxDelegate(string text);

    public partial class Form1 : Form
    {
        void updateTextBox(string text)
        {
            textBox.Text = text;
        }
        public Form1()
        {
            InitializeComponent();
            Go();
        }
        public void Go()
        {
            textBox.Text = "START";
            DoWork dW = new DoWork(); //<= instance of work class
            Thread myThread = new Thread(dW.WorkInBeckground);
            myThread.IsBackground = true;
            myThread.Start();
        }
    }
    public class DoWork
    {
        public void WorkInBeckground()
        {
            while (true) //loop and wait for data
            {
                // Listen some ports and get data
                // If (data==ok) update main UI textbox with status
                Form1 myForm = new Form1();  //<= instance of main class
                myForm.Invoke(new updateTextBoxDelegate(???updateTextBox), new object[] { "BUFFER LOADING..." });
                Thread.Sleep(1000);
                // Continue looping.....
            }
        }
    }
}
  • 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-12T10:57:07+00:00Added an answer on May 12, 2026 at 10:57 am

    You need to use a threadstart object and pass in a reference to your form object. What you are actually doing is creating a new reference to your mainform, which in turn kicks off a thread, which in turn does the same thing.

    So just use a paramaterizedthreadstart object to kick off your thread, passing in “this” and you should be fine.

    MSDN ParameterizedThreadStart

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

Sidebar

Related Questions

I have this problem in a project I'm working on: I have a list
I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
I'm working on a project but i have a problem I have an object
I'm working on project with listview,but I have a little problem. I'm using SimpleAdapter
So I have a little bit of a problem. I working on a project
I'm working on a project where I have 2 web services that need the
I am working on a small project and i have got a problem. If
I have a problem with MySql primary keys, it's for my project i'm working
I have a problem that I'm working in nHibernate project that have the following
I am working on an Android project and have a problem with SQLite database

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.