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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:41:05+00:00 2026-05-27T17:41:05+00:00

I am working on the following program which deals with threads and thread priorities.

  • 0

I am working on the following program which deals with threads and thread priorities.

I have constructed a windows form containing a rich textbox (DisplayTextBox) and two buttons (StartButton for running app and ExitButton for closing app).

In the form, I am creating several threads and running them one after another. The method used by each thread is found in the Threading class. The method in question is PrintOnScreen().

In this method, I am appending the thread name as well as its priority to str of type StringBuilder. Then I want to display the contents of str in DisplayTextBox (which is in Form.cs).

However, I am getting a “NullReferenceException was unhandled: Object reference not set to an instance of an object” error. The line where the error crops up is the following:

DisplayTextBox.Text = Convert.ToString(str);

Can you please help me to solve this error? Thanks.

Edit

Thanks to all for your help. In order to solve the problem, I copied the PrintOnScreen method to the Form.cs class and discarded Threading.cs.

I later used the code given by Anand and placed it below t2.Join(). Now it works like a charm.

  • 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-27T17:41:06+00:00Added an answer on May 27, 2026 at 5:41 pm

    The problem occurs in the constructor of your form. You declare DisplayText again as local member, so that the field of your form isn’t initialized. Change your constructor like this:

    private void Form1_Load(object sender, EventArgs e)
    {
        DescTextBox.Visible = false;
        DisplayTextBox = new RichTextBox();
        DisplayTextBox.Location = new Point(15, 31);
        DisplayTextBox.Height = 258;
        DisplayTextBox.Width = 303;
        panel1.Controls.Add(DisplayTextBox);
    } 
    

    and it should work like you expect.

    Edit: But beware of the problems you will get, when you want to change UI elements from a background worker thread. In those cases you will have to use the invoke pattern.

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

Sidebar

Related Questions

I have a very old, very very large, fully working, C program which plays
I have a simple program which starts n threads and create some load on
I have a normal windows forms program (Not VSTO) which deploys using click once.
I am working on a Windows utility program which communicates with some custom hardware
I have written a program which reads input from csv file and its working
I have a C++ program which is working quite well using OpenMP to parallelize
I have been working now for few days on a small C program which
I have the following working tar -pcvf base.tar input/myPacket/my2 --exclude-vcs input/myPacket/my3/*.bmp When i have
In tcsh , I have the following script working: #!/bin/tcsh setenv X_ROOT /some/specified/path setenv
I am altering the question now! I have the search working using the following:

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.