Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Writing an OCX with Windows sockets server and a DB client as two internal threads

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.

0
hemantmadaan
Asked:
hemantmadaan
1 Solution
 
pratap_rCommented:
hi hemantmadaan

WM_QUIT will cause the parent process to terminate if left unhandled. Since OCX is loaded as a child by VB IDE the WM_QUIT is causing VB to close.

You should inturn close the thread... or just dont do anything inside the thread's run.. Its the design mode thats causing the problem.

repost if you need further clarification. think i will be able to help u

+Pratap
0
 
CleanupPingCommented:
hemantmadaan:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now