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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:13:38+00:00 2026-06-01T07:13:38+00:00

Well I have this code in my Managed C++/Cli in Visual Studio 2008, I

  • 0

Well I have this code in my Managed C++/Cli in Visual Studio 2008, I want to be able to access the windows forms items inside of the callback of the Thread Function, and I can’t, it generates an error.
Is there another way to do that? to be able to modify the GUI stuff inside of a method of the WinForms Class by using the Thread function callback ?

This example shows what I want to do.

I need to use a thread because I want to have the other things in the Forms to be accessible, and without using threads everything just freezes until everything is done, and the “Login” function it calls, takes some time because it does HTTP Requests. and after this HTTP Request I set the values that I got from it in a Form Element.

void Login(){
    this->btn_next->Enabled = false;

    this->login_accounts_facebook->Enabled = false; //This gives an error probably because of accessing "this->"
        if(this->clb_contas->CheckedItems->Count <= 0){
             //...
        }
}

System::Void test_login_Click(System::Object^  sender, System::EventArgs^  e) {
    ThreadStart^ start = gcnew ThreadStart(this, &Login_Test::Login);
    Thread^ t = gcnew Thread(start);
    t->Start();
}

Does anybody know how could I do that? if you think this can’t be done and you want to suggest something something to make the GUI available while doing the process, I’m open for suggestions.

I hope I was being clear enough.
Thanks in advance.

  • 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-01T07:13:40+00:00Added an answer on June 1, 2026 at 7:13 am

    All UI related code should be executed on the UI thread. In your case, that means that only the code you denoted with //... should be run on a separate thread. Extract that long-running code in its own method and pass that method to ThreadStart instead of Login(). Then you’ll need to arrange for a way for the worker thread to notify the UI thread if and when it’s complete.

    Update:

    Here’s a crude example of how to modify your code. I would prefer to extract the long running operation in its own class if it is of sufficient complexity, but I think you get the idea.

    The call to BeginInvoke ensures that LongRunningOperationComplete will be executed on the form’s UI thread. You can use the same approach to call other methods that update the UI to indicate progress, even while the time-consuming operation is still running. If those methods require more parameters, you can create different delegates with the appropriate signature, and pass those parameters in the call to BeginInvoke. See here for how to do that.

    // Same signature as LongRunningOperationComplete
    delegate void MyInvokeDelegate();
    
    void LongRunningOperation() {
      for (int i=0; i < 100; i++) {
        Thread::Sleep(100);
        // The actual work that you're doing
      }
    
      // Operation complete. Update UI.
      this->BeginInvoke(gcnew MyInvokeDelegate(this, &Login_Test::LongRunningOperationComplete)); 
    }
    
    void LongRunningOperationComplete() {
      this->btn_next->Enabled = true;
      this->login_accounts_facebook->Enabled = true;
    }
    
    System::Void StartMyLongRunningOperation() {
      ThreadStart^ start = gcnew ThreadStart(this, &Login_Test::LongRunningOperation);
      Thread^ t = gcnew Thread(start);
      t->Start();
    }
    
    void Login() {
      this->btn_next->Enabled = false;
    
      this->login_accounts_facebook->Enabled = false; //This gives an error probably because of accessing "this->"
      if(this->clb_contas->CheckedItems->Count <= 0){
        StartMyLongRunningOperation();
      }
    }
    
    System::Void test_login_Click(System::Object^  sender, System::EventArgs^  e) {
      Login();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,
I have seen this answer https://stackoverflow.com/a/9243472/563381 And while it works well visual as soon
I am having a funny with my C++ managed code with visual 2008. I
Well lets say we have this c# code: public override void Write(XDRDestination destination) {
I often have code based on a specific well defined algorithm. This gets well
Well currently I have this: <rich:fileUpload addLabel=Agregar clearAllLabel=Quitar todos clearLabel=Quitar deleteLabel=Quitar doneLabel=Completado uploadLabel=Subir archivos
I have this linq query that works well (although it may be written better,
I have this structure in my html document: <p> <em>You</em> began the evening well,
I have tested this servlet and it works well, except in Google Chrome it

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.