Thread with 500 points and Grade A

I am a server listening to the client and receiving the message from the client periodically. This is under one thread.
Actually the situation is........

When I click on the button ....The event handler in the button creates a new thread for me and handles the messages that I receive from the client and in the Button handler I need to Paint the form accordingly as per the  messages received from the client.

Here is the code......

 public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

ThreadStart ^myThreadDelegate = gcnew ThreadStart(this, &CppDraw::Form1::repeat);
                                     trd = gcnew Thread(myThreadDelegate);



Outside the button handler.......

private: void repeat()
      FILE *fd;

    fd = fopen("rd_log1.txt","w");


        iResult = recv(s,buffer,256,NULL);


        fprintf(fd,"\n\n The value of iResult is %s \n\n ",buffer);


Here my issue is when I receive the message from the client inside the thread I want to pass this data to the clent and paint the form accordingly.....

Any idea on how to do this.........
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Deepu AbrahamR & D Engineering ManagerCommented:
Inside the thread do a postmessage() to the button handler using the valid window handle. That will solve your problem.
Best Regards,
tatikor_143Author Commented:
Can U post some sample code .........

Its highly appreciated.....
Deepu AbrahamR & D Engineering ManagerCommented:
//Calling a thread
hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)MyThreadProc,this,0,NULL); // 'this' is the class object from which you call the thread.

//Thread proc

// CMyClass* pMyclass = reinterpret_cast<CMyClass*>(lpVoid); assume that you are passing CMyclass object.
// pMyClass-> Call any funtion...if you wish...
//pass a valid handle to the window in which you want to post the message...pMyclass->m_hWnd
 ::PostMessage(pMyclass->m_hWnd, WM_MYBUTTON, (WPARAM)0,(LPARAM)0);


In you dialog class header

#define WM_MYBUTTON      WM_USER+1


Hope this will give you the may need to tweak it a bit to make it work on your program..
Please shout if you need more help...

Best Regards,
Its better to use PostMessage so the worker thread doesn't have to wait while the main thread processes.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tatikor_143Author Commented:

I am using WM_COPYDATA to resolve the above issue . I am able to send the data but not able to receive it....

How to implement...............


tatikor_143Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.