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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:29:11+00:00 2026-05-28T01:29:11+00:00

I already asked something similar, but the solution I found help me partially, so

  • 0

I already asked something similar, but the solution I found help me partially, so I’m asking a question that is similar to my previous one.
my problem is that in the Thread I want that the text of the button change.
the thread works fine, I can see the MessageBox I’m displaying, but the text of the button remains unchanged.
how do I change it?
if I need to use the delegate (commented text), ho do I I fix it? because that code raises some errors about wrong ‘(‘ and ‘{‘ but that’s the answer I got before

#pragma once


namespace UIThread {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Threading;

/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
///          'Resource File Name' property for the managed resource compiler tool
///          associated with all .resx files this class depends on.  Otherwise,
///          the designers will not be able to interact properly with localized
///          resources associated with this form.
/// </summary>


public ref class Form1 : public System::Windows::Forms::Form
{

public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Button^  BtnStart;
protected: 

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        this->BtnStart = (gcnew System::Windows::Forms::Button());
        this->SuspendLayout();
        // 
        // BtnStart
        // 
        this->BtnStart->Location = System::Drawing::Point(114, 38);
        this->BtnStart->Name = L"BtnStart";
        this->BtnStart->Size = System::Drawing::Size(124, 37);
        this->BtnStart->TabIndex = 0;
        this->BtnStart->Text = L"button1";
        this->BtnStart->UseVisualStyleBackColor = true;
        this->BtnStart->Click += gcnew System::EventHandler(this, &Form1::BtnStart_Click);
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(284, 262);
        this->Controls->Add(this->BtnStart);
        this->Name = L"Form1";
        this->Text = L"Form1";
        this->ResumeLayout(false);

    }
#pragma endregion
private: System::Void BtnStart_Click(System::Object^  sender, System::EventArgs^  e) {
    Form1^ f=gcnew Form1;
    Thread^ oThread = gcnew Thread( gcnew ThreadStart( f, &Form1::ThreadMethod ) );
    oThread->Start();
}

private: void ThreadMethod(/*Object^ state*/)
{   
    BtnStart->Text="hello";
    MessageBox::Show("AAAAAA");
    //this->Invoke((Action^)delegate(){BtnStart->Text = "Hello";});
}
};

}

  • 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-28T01:29:11+00:00Added an answer on May 28, 2026 at 1:29 am

    You managed to get rid of the runtime exception that told you that you were doing it wrong. By creating a new form object. One that isn’t visible because you never called its Show() method. So you can’t see the button text update either. What you want to do is update the existing form object:

    System::Void BtnStart_Click(System::Object^  sender, System::EventArgs^  e) {
        Thread^ oThread = gcnew Thread( gcnew ThreadStart( this, &Form1::ThreadMethod ) );
        oThread->Start();
    }
    

    You got bad advice on your previous question, that syntax only works in C#. C++/CLI doesn’t support anonymous delegates. You have to write it out, just like you did for the ThreadStart delegate:

    void UpdateButton() {
        BtnStart->Text="hello";
    }
    
    void ThreadMethod() {   
        this->Invoke(gcnew MethodInvoker(this, &Form1::UpdateButton));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Searching here I found that this question was already asked , but I think
I already asked a similar question but this one is a bit different/specific: I'm
I know this is a similar question to one already asked, but I was
I know a similar question has already been asked, but that retrieves all the
i've already asked something similar, but now i've the problem to manage and realize
I already asked this question at the JOS-.NET board but Joel is closing that
I already asked a similar question, PE Header requirements , but I'm not really
Sorry to ask something that others have already asked. But when I use the
(I've already asked the similar question and it turns out that my client key
I know I've already asked questions on this, but something that's just confusing. I'm

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.