Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows sockets server and a DB client as two threads of a same OCX

Status
Not open for further replies.

hemantmadaan

Programmer
Mar 27, 2003
5
IN
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 craching the complete VB IDE. Please help me in this regards. I really need to finish this soonest possible.

Thanks a lot.
 
The fact that it's crashing the VB IDE is not so strange. Your test app, your ocx and the IDE run in the same process, so if your ocx crashes, so will the rest...

However, you have not nearly given us enough information to even start thinking about what may be wrong with the OCX.

Try debugging the OCX in the VC editor and see where it crashes. For all you know it's not even a threading issue.
Greetings,
Rick
 
ok let me elaborate a bit more,

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.

Please help.
 
Maybe a silly question of mine, but do you send the WM_QUIT messages to the secondary thread, or is also being send to the main thread of your OCX?
Greetings,
Rick
 
Was that a joke... :)

Anyways, yeah I am maintaining two pointers each for threads and send WM_QUIT using PostThreadMessage API of CWinThread.

I hope that helps.
 
Actually what I meant was: does the main message loop of your control also exit, or is it just threads you created yourself.

If you kill the main messageloop then I don't know what may happen, since the container is still alive (and maybe kicking).

Is it maybe crashing in some cleaning up you might be doing before/after the threads exit. It's perfectly legal to kill any threads you created yourself, it just might be you corrupt something.


Greetings,
Rick
 
I checked at my part. I am not doing any such silly thing like killing my own main thread. The VB is still crashing, I have a hunch that it might be due to some threading model used in the project.

Kindly see and help me with these details.
 
You'll have to figure out in the debug windows exactly at what line of code it crashes I guess....
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top