All my communication using this delegate and function are great between forms, but this thread for receiving compiles and all, but then throws this error. I have posted the important sections of my code. If you think I need more, let me know. Thanks.

I am getting a Cross thread operation not valid: Control "Label1" accessed from a thread other than the thread it was created error.

In my rs232 thread I have

unsigned char messageBuf[512];

Rs232com->Parity = Parity::None;
Rs232com->DataBits = 8;
Rs232com->StopBits = StopBits::One;

int index = 0;

	messageBuf[index] = Rs232com->ReadChar();
	index ++;
while(messageBuf[index - 1] != (char)0x3F);

messageBuf[index - 1] = (char)0x0;


if(messageBuf[0] == (char)0x01)

String^ update = "GO";

DataArch is an instance of my dataclass that I pass around the forms as well as this thread.

Then in my main form

public delegate System::Void SendStringDelegate(System::String^ name);

MainForm(DataSource^ DataArch)
           DataClass = DataArch;

           rs232->NameChangeCallbackFn = gcnew SendStringDelegate(this, &WCS::MainForm::NameChangeCallbackFn);

private: System::Void NameChangeCallbackFn(System::String^ name) 
           //if (this->InvokeRequired)
	           // Invoke(gcnew SendStringDelegate(this, &WCS::MainForm::NameChangeCallbackFn));

            this->label1 = DataClass->getlabel1();    //Line of the error

I know I have to use invoke, but I dont know how to implement it. Any help would be appreciated. Thanks.

Could someone at least explain invoke and how it is used? or link me to something that may make sense. Ive been googling and cant find anything that I understand. Thanks either way.

This article has been dead for over six months. Start a new discussion instead.