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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:35:24+00:00 2026-05-27T16:35:24+00:00

I have one main windows form and within that form I have custom controls

  • 0

I have one main windows form and within that form I have custom controls that represents different screens in application. I want to access this control’s child controls. There’s something I’m not getting here…sometimes I get this error:

Cross-thread operation not valid: 
Control 'lblText' accessed from a thread 
other than the thread it was created on.

but sometimes everything works OK. I don’t completelly understand why the error…probably something with external device (MEI BillAcceptor) which has an event (inside Form1 class) that does the changes to the control… so let me write a simple code…

//user control
public partial class Screen2 : UserControl
{
    public void changeValue(string txt)
    {
        lblText.Text = txt;
    }
}

and the method changeValue is called from a form1 when particular event is rised…

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        BillAcceptor.SomeBillAcceptorEvent += 
            new SomeBillAcceptorEventHandler(changeText);
    }

    private void changeText(object sender, EventArgs args)
    {
        _screen2.changeValue("some text");
    }
}

So the most annoying thing is that sometimes everything actually works… So my question is “do I have to use Invoke here?” or how do I solve this with less changes to the application…

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

    Yes you need to use Invoke if there is a possibility of that method being called from a different thread.

    You can check this.InvokeRequired(), if true, then use invoke, if false do a normal call.

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

Sidebar

Related Questions

I have WPF Application where I have One main form and other user controls
I have an application that has two threads. The first one (the main thread)
I have a windows form application that will open other forms, but will only
In my WPF application, I have a ListView on the main form that displays
I have one main parent swf that loads several other swfs. If something happens
With a distributed application, where you have lots of clients and one main server,
I have a web project that I developed where one of the main functions
I have a windows forms project. It has a main form derived from System::Windows::Forms::Form
I have a borderless Windows Forms application. The main window creates other forms (simple
I have a windows form application which needs to be the TopMost. I've set

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.