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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:53:31+00:00 2026-06-16T00:53:31+00:00

Trying to update my label from another thread through an interface and a delegate.

  • 0

Trying to update my label from another thread through an interface and a delegate. In debug mode it says the label property is set to the message. But I see nothing at the form itself.

Working in .NET 4.0

A small representation of what I am using:

My Interface:

public interface IMessageListener
{
    void SetMessage(string message);
}

the form where I implement it:

public partial class Form1 : Form, IMessageListener
{
...
    public void SetMessage(string message)
    {
        SetControlPropertyValue(ColoLbl, "Text", message);
    }

    delegate void SetControlValueCallback(Control oControl, string propName, object propValue);
    private void SetControlPropertyValue(Control oControl, string propName, object propValue)
    {
        if (oControl.InvokeRequired)
        {
            SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
            oControl.Invoke(d, new object[] { oControl, propName, propValue });
        }
        else
        {
            Type t = oControl.GetType();
            PropertyInfo[] props = t.GetProperties();
            foreach (PropertyInfo p in props.Where(p => p.Name.ToUpper() == propName.ToUpper()))
            {
                p.SetValue(oControl, propValue, null);
            }
        }
    }
 }

the class where I try to set the message through the interface. This class is being run from another thread:

public class Controller
{
    IMessageListener iMessageListener = new Form1();
    ...
    public void doWork()
    {
        iMessageListener.SetMessage("Show my message");
    }
 }

The code compiles all fine, when stepping through with debugging the property of the label does get set, it just doesn’t show on the form itself for some reason.

I suspect it’s either I am missing a line somewhere, or the way the Controller class handles the interface what causes the problem. But i can’t figure out why or what exactly.

  • 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-16T00:53:33+00:00Added an answer on June 16, 2026 at 12:53 am

    The Text property of ColoLbl won’t change in the Form1 previously loaded when you call iMessageListener.SetMessage("Show my message"); in your code because iMessageListener was initialized as a new Form1();. It may only change in the new instance created.

    IMessageListener iMessageListener = new Form1();
    

    If you are trying to change ColoLbl value in Form1 which was initialized before, do not initialize a new instance of Form1. Instead, initialize an IMessageListener which links to the Form1 created previously.

    Example

    //myFormSettings.cs
    class myFormSettings
    {
        public static Form1 myForm1; //We will use this to save the Form we want to apply changes to
    }
    

     

    //Form1.cs
    private void Form1_Load(object sender, EventArgs e)
    {
        myFormSettings.myForm1 = this; //Set myForm1(the form we will control later) to this
        Form2 X = new Form2(); //Initialize a new instance of Form2 as X which we will use to control this form from
        X.Show(); //Show X
    }
    

     

    //Form2.cs
    IMessageListener iMessageListener = myFormSettings.myForm1;
    iMessageListener.SetMessage("Show my message");
    

    Thanks,

    I hope you find this helpful 🙂

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

Sidebar

Related Questions

I am trying to update a label from one form to another. the code
I'm trying to update the text of a label from a seperate class on
When trying to update a subversion working copy from Netbeans, I get the following
I`m trying to update time in datetime field as UPDATE table_name SET col_name=to_DATE('04/02/2012 00:12:00','MM/DD/YYYY
I am trying to retreive text from another application by app's control handle. I
I’m trying to migrate a few models from one Django app to another and
I am trying to update selected rows of UITableView from UIAlertView inside didSelectRowAtIndexPath .
Following on from a previous post , I'm trying to update a database field
I am trying to update some (but not all ) prices from one store
Trying to update some old code from live() to use on() and something is

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.