[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Creating a thread, letting it execute, then go away on its own

Experts,

If I create an ActiveX EXE, use CreateObject from a client program to run a function in this ActiveX EXE, is there a way for that object to just "end" without the client system having to manage it?  What I want to is have a main program accept TCPIP connection, had the connection off to a thread, then after the thread responds, just goes away.  If I do this now, the client that created the thread has problems.

Thanks

onemorecoke
0
onemorecoke
Asked:
onemorecoke
  • 3
  • 2
1 Solution
 
clarkscottCommented:
If you 'activate' the component in your program - then use it - then set it to NOTHING - it will go away.

1.  Dim the object
2.  Call the function
3.  set object = nothing


Note: appartment threaded components will 'stay alive' until nothing is using it.  If you have 3 users using the component, it will remain 'active' until the last user is out.

Scott C.
0
 
onemorecokeAuthor Commented:
Scott,

If the function being called in the object launches something that is asynchonous in the object, the control is returned back to the client, then the object is set to nothing, will the object stick around until the blocking is over or will the object go away?  Does in-process/out-of-process objects makes any difference?

I just remember one launching MS Word by creating an object in a VB app, I would shut down the VB app, but Word would stick around.  That is what I am shooting for.

Thanks

onemorecoke
0
 
clarkscottCommented:
Once the object is set to nothing - per specific app - the object should go away.  You can view this by examining your task manager.  You should see it while set and not see it when set to nothing.

If you run 3 concurrent apps calling the same component, and have each set the component, the component should be visible on the task manager (a single instance if appartment threaded) until each app has set the component to nothing.

Scott C.
0
 
onemorecokeAuthor Commented:
Scott,

Sorry for the long delay in responding. Let me get more specific. I have an app with a DAEMON that listens on port 80.  When a request comes in, what I want to do is assign the request to a tcp control in an activeXEXE component, have the activeX component respond to the request, then that thread go away. I need the thread to work independently, then go away.  I would liken it to just lauching another exe that responds then ends. The reason I want to do this is because I will be getting 30-50 requests per second so it needs to be multithreaded.  I believe the example you first gave wont work because I am not just executing a function, but handing off a conversation that needs to continue until finished. So, it is a webserver bascially but able to handle alot of traffic without getting stuck handling one request at a time.  Most of the requests will be fast, but other may require a database lookup that will kill the other requests if it takes awhile and I am not multithreaded.  I have written the main app to add the objects created into a collection, scanned the collection to see which threads are done, and then set them to NOTHING, but in a really high performance environment, those scans of the objects take forever and lock up the main app while scanning.  Anyway, that is where I am at.

Thanks for your responses

onemorecoke


0
 
clarkscottCommented:
If I understand you correctly.....

I think you want to set up for Apartment Threading.  This makes the single component (single instance of the component running) handle multiple calls.  The single component will 'stay alive' until all users are finished with it.

It's not in the code - it's how you create your component.


There can still be issues with a lot of users pounding on a component.  That's why Microsoft developed their Transaction Server (MTS).  It is a way of having something oversee and control the resources so things go smoothly.  If 10,000 users try to hit the component at the same time....  

Scott C
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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