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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:13:06+00:00 2026-06-13T09:13:06+00:00

I’m now implementing the network program using the namedpipe and C#. Within the server

  • 0

I’m now implementing the network program using the namedpipe and C#. Within the server program’s main method, I started one thread named “ReadingMessage” which is to read the messages from the client program. In this thread, it needs to change the properties of controls (Text of textbox, Position of labels, etc.) based on the messages returned from the client. Therefore, it had cross-threaded errors in this procedure (“ReadingMesssage between UI thread”). I found out that there are two ways to solve this problem

  1. Invoke the controls using Delegate
  2. Form.CheckForIllegalCrossThreadCalls = false;

I tested both of them but there is one problem. When the form started as first time, the properties of control are changed without any errors. When the form is closed and started again as second time, the properties of control are not changed and any error messages are not shown. I catch the breakpoint to the code where the properties of controls are instructed to change. The code run smoothly but the problem still occurs.

I don’t know what’s that problem. Therefore, if anyone knows this problem, please suggest me…

Update: (Posting Code and Correcting some errors in my first question)

The thread is not in the main method of server program. I was wrong because I wanted to describe my question in short. Now, I will describe my question in more detail. There is one button click event in the main form of server program.

//Main Form
public partial class MainForm : Form
{
    private void btnButton_Click(object sender, EventArgs e)
    {
       AnotherForm aform = new AnotherForm(); //This is the form where threading run
       aform.show();    
    }
}

//AnotherForm
public partial class AnotherForm : Form
{
    private void CargoLoading_Load(object sender, EventArgs e)
    {
        (new System.Threading.Thread(readingMessage)).Start(myPipe);    
    }
}

private void readingMessage(Object myPipeObject) //Read the messages send from the client machine
{
     while (true)
     {
         //Code of serverstream
         SetTextofTextBox1("AnyText"); //Code where the properties of control are instructed to change
     }
}

private void SetTextofTextBox1(string text)
{
     if (this.txtTextBox1.InvokeRequired) //the debugger return false at second time of this form is opened
     {
         SetTextCallback d = new SetTextCallback(SetTextofTextBox1);
         this.Invoke(d, new object[] { text });
     }
     else
     {
          this.txtTextBox1.Text = text;
          this.txtTextBox1.Update();
     }
}

That’s all the code where problem occur. When “AnotherForm” is open as first time, it’s OK. But it is opened again as second time, the properties of control (text of TextBox1) is not effected and not changed. At there, I noticed that the debugger return false to Control.InvokeRequired at this second time. Really sorry for all for long question because I’m a novice as a programmer.

Still expecting your suggestions…

Update 2:

Finally I tried all the ways but it doesn’t come out the best solution. Therefore, I would like to suggest all to just avoid this condition and re-write some of your code in another concept when u meet this situation like me.

  • 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-13T09:13:07+00:00Added an answer on June 13, 2026 at 9:13 am

    From your background thread, you should use Control.InvokeRequired and Control.Invoke in order to cause the UI thread to execute the code that updates the UI.

    Only the UI thread is allowed to “touch” control properties, so your background thread cannot update them.

    To be more specific, in case you’re interesting in more details: in Windows, each form and control usually have 1 or more HWND associated with them. An HWND is a handle to the Windows operating system object representing a Windows window.

    Each HWND is always associated to a specific thread, the thread that created it. Any Windows message sent to that HWND will reach that thread’s message queue and must be handled by that thread’s message loop.

    When you make seemingly innocent calls to Controls methods, the implementation of these methods might sometime destroy and create HWND under the hood (for example, creating a submenu for a Menu control or adding a button to a Toolbar control). Now, if you were to make such calls from different threads, you would end up with HWNDs belonging to different threads, and the processing of your controls’ messages would be broken.

    For that reason, all access to controls’ methods are prohibited from any thread other than the thread that created the control’s HWND (e.g. the thread on which `Control.CreateControl() was called).

    In the bottom line, for most simple applications, the main thread is the only one creating windows, and so you should be touching Forms and Controls only from your main thread.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.