?
Solved

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

Posted on 2003-03-28
3
Medium Priority
?
233 Views
Last Modified: 2012-05-04
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
Comment
Question by:hemantmadaan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
pratap_r earned 160 total points
ID: 8228576
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
 

Expert Comment

by:CleanupPing
ID: 9446690
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question