Writing an OCX with Windows sockets server and a DB client as two internal threads
Posted on 2003-03-28
I am facing this difficulty as I am a beginner in OCX programming and know nothing in writing and using simultaneous threads in an OCX to be used in a project in VB.
One thread is used to run as a socket server accepting the connections and then messages on some port.
Next thread pings DB server at a apecific interval and gets the data from there.
I started writing the component using MFC OCX wizard, I am able to start the threads using AfxBeginThread. Both the threads are using one global variale bServerRunning which I set to false to stop the two threads.
I tested this component with a VB test application and in the end its crashing the complete VB IDE. Please help me in this regards. I really need to finish this soonest possible.
I created two classes CPingServer and CListenServer derived from CWinThread. I want these threads to only start when the control comes in a running user state. I am checking this in DoPropertyExchange and when the userMode becomes design time again, I am sending WM_QUIT messages to bith the threads. But as I do this it kills the main thread of Vb too and VB quits completely without notifying.
Is it something to threading model, if yes, then how should I do it, how should I run both the threads simultaneously or for instance change the threading model to muti apartment threading as I think required in this case.
I checked an example OCX code and it is working fine, even it is stopping a thread, but the only difference is it is doing it in Destroy method of OCX control. But I want to check this every time state changes in our case.
People Please help me get thru this as it is very urgent.