how to edit controls in a system::thread

Posted by Ian Lundberg on Stack Overflow See other posts from Stack Overflow or by Ian Lundberg
Published on 2012-12-20T05:01:53Z Indexed on 2012/12/20 5:02 UTC
Read the original article Hit count: 168

Filed under:

I need to be able to add items to a listbox inside of a thread. Code is below.

1. ref class Work
2. {
3. public:
4.  static void RecieveThread()
5.      {
6.      while (true)
7.      {
8.          ZeroMemory(cID, 64);
9.          ZeroMemory(message, 256);
10.         if(recv(sConnect, message, 256, NULL) != SOCKET_ERROR && recv(sConnect, cID, 64, NULL) != SOCKET_ERROR)
11.         {
12.             ID = atoi(cID);
13.             String^ meep = gcnew String(message);
14.             lbxMessages->Items->Add(meep);
15.             check = 1;
16.         }
17.     }
18. }
19. };

I get the error Error: a nonstatic member reference must be relative to a specific object on line 14. Is there any way to get it to let me do that? Because if I try to use String^ meep; outside of that Thread it doesn't contain anything. It works PERFECT when I use it within the thread but not outside of it. I need to be able to add that message to the listbox. If anyone can help I would appreciate it.

© Stack Overflow or respective owner

Related posts about c++-cli