Keep Sub Main running while a thread executes

P

pmclinn

I have created an app that pulls down data from some Network Devices
via threaded proceedures. This proceedure runs inside of a exe.

The program collects the list of devices to scan from a txt list and
then issues out 6-7 queries at a time.

When the 25 queries return the data I write the info to oracle.

The problem is that the Sub Main ends before the threads complete. In
the Design-Debug mode I send up an invisible form (showdialog) and
leave it open until all my threads complete.

This trick does not work though when I run the exe from my desktop
though, in a production environment. The program opens the dialog but
no code fires.

I tried putting in a loop that checks to see if the threads are all
complete but it really seems to burn up cpu time.

What is the best way to handle this type of issue?

Basically I want the sub Main app to stay open until I say close....
 
A

Arthur Dzhelali

Try look into AutoResetEvent

Private Shared ARS As New AutoResetEvent(False)

PUT IT IN SUB MAIN
ars.waitall(ARRAY OF YOUR THREADS)

after you put it you can in your sub main it will stall the execution till
all threads are finished.

Problem with that your sub main might stay open if one of the the threads
errors out and you don't have any error handling on thread.

you can set it up with time out.

I hope it helped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top