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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:20:15+00:00 2026-05-27T14:20:15+00:00

I have a VC++2008 Form Application with some unmanaged socket communication code. I want

  • 0

I have a VC++2008 Form Application with some unmanaged socket communication code. I want to display the communication message on the form. In order to avoid above error, I have added delegate method and used the Invoke call. But I still get above error. Anybody can help me correct my code?

This is the Form1 header file:

#pragma once

#include "SocketClientMgr.h"
class SocketClientMgr;

namespace SocketClientFormApp {

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            updateHandler = gcnew ProgressHandler(this, &SocketClientFormApp::Form1::updateLogMsg);
        }
    protected:
        ~Form1()
        {
        }
    private:

#pragma region Windows Form Designer generated code

        void InitializeComponent(void)
        {
        }
#pragma endregion

///////////////////////////////////

    private: delegate void ProgressHandler(String^ msg);
    static ProgressHandler^ updateHandler;

    public: void appendMsg(String^ msg);
    public: void updateLogMsg(String^ msg);
};
}

This is the Form1 cpp file:

#include "stdafx.h"
#include "SocketClientForm.h"

using namespace SocketClientFormApp;

void Form1::appendMsg(String^ msg)
{
    updateHandler->Invoke(msg);
}

void Form1::updateLogMsg(String^ msg)
{
    msgDisplayBox->AppendText(msg);
}

The appendMsg() method will be called from another class in another thread.

EIDT:

static ProgressHandler^ updateHandler; static should not be there and it should be private

error happened at updateLogMsg()
enter image description here

  • 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-27T14:20:16+00:00Added an answer on May 27, 2026 at 2:20 pm

    A delegate’s Invoke(args) just runs on the current thread; you need someControlInstance.Invoke(delegate, args) (quite commonly, “this.Invoke(…)”), which uses the message loop to transfer the delegate call to the UI thread, avoiding the cross-thread issue.

    Equally;

    • Delegate.BeginInvoke uses the ThreadPool
    • Control.BeginInvoke uses te message-loop
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

VB 2008. I have several text boxes on a form and I want each
I have a Windows Form Application in Visual Studio 2008 - PictureBox.Refesh() method causes
I have created a Windows Form Application using Visual C# 2008 Express Edition with
I have problem in writing the code in windows form application my problem is
I have c#/2008/winform application. I have a form with a picture banner, and a
I'm using VB 2008 express to create a windows form application. I have a
I have a visual c++ windows form application (empty) made on visual studio 2008
JI have written a .NET C# Windows Form app in Visual Studio 2008 that
IDE: Microsoft Visual Studio Professional 2008 Language: C# Background: I have one form and
c# .Net 3.5 visual studio 2008, windows xp I have a main form in

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.