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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:03:25+00:00 2026-05-25T16:03:25+00:00

m having problem in operating on richtextbox from another class m using backgroundworker class

  • 0

m having problem in operating on richtextbox from another class

m using backgroundworker class to seperate GUI thread from the computation thread

this is the function i need to call from other class

public void UpdateRTB(String strText, Color colVar)
    {
        if (InputBox.InvokeRequired)
        {
            InputBox.Invoke(new UpdateRTBCallback(this.UpdateRTB), new object[] { strText, colVar });
        }
        else
        {
            InputBox.Select(InputBox.Text.IndexOf(strText), strText.Length);
            InputBox.SelectionColor = colVar;
            InputBox.Update();
        }
    }

the variable objForm1 is the variable declared after initialization of the form as

objForm1 = this;

the function which return the form is

public static Form1 GetThisForm()
    {
        return objForm1;
    }

this is my delegate which is declared globally

public delegate void UpdateRTBCallback(String strText, Color strColor);

this is the code m writing in another class to call it

Form1 form1 = Form1.GetThisForm();
form1.UpdateRTB(item, Color.Yellow);

in the objForm1, when I debug I see the fields of it is showing System.InvalidOperationException.. is this the problem of I’m doing something wrong
Please help!!!

  • 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-25T16:03:25+00:00Added an answer on May 25, 2026 at 4:03 pm

    OK, I’m guessing there’s a second possible scenario. The reference to your form gets set after initialization of the form so I guess that’s in your form constructor (and I hope it’s after InitializeComponent() according to the WinForms guidelines..). The function that returns the reference is static, which means the reference also has to be static, which means you could be looking at it before the constructor of the form got called and before the reference got set. Here I’ll have to add you did not show us where you are accessing the reference from (from a (static) function that ran before the form got constructed?).

    Anyway, here are some alternatives I’m hoping will be a useful answer / option to you -> instead of writing your own you may want to have a look at these useful helper properties that seem to already do what you need Form.ActiveForm or Application.OpenForms.

    PS: System.InvalidOperation may show up for your form’s fields because they too are being evaluated from another (debug) thread than the UI thread.

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

Sidebar

Related Questions

I am having problem in getting reference of Ajax control extender using $find() or
I'm having problem selecting an element with an id like this <li =0f:Bactidol_Recorder.mp4>. I
It's not the first time I'm having this problem, and it's really bugging me.
Actually, the problem is like this:- i am having a table, say Payments. I
I am having a problem returning an ArrayList from my web service (Java). I
http://imageshack.us/photo/my-images/189/unledgev.png/ i h'v having problem with finding the radius of this circle. i converted
I'm having a problem with sprintf() , using it to store a mysql query
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
We're having problem with a huge number of legacy stored procedures at work. Do
I'm having problem in the following line: rd.PrintOptions.PaperSize = PaperSize.PaperFanfoldStdGerman; it throws an exception

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.