Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1530

VB6 Threading, using the small DirectCOM.dll-HelperLib

$
0
0
Just for those who want to try a proven approach, which works reliably (and comparably simple)
in spanning up STAs (Single-Threaded-Apartments) for over 10 years now (one can use his own
VB6-compiled AX-Dlls which provide a Class-Instance that runs on said STA - no Assembler-Thunking,
no TypeLibs and also no "special Dll-Exports" are needed - it's aside from a few API-calls just straight VB-Code).

The Thread-Class-Instances in question are always created Regfree in this case (so,
no Setup is needed - just ship your Thread-Dlls alongside DirectCOM.dll in a SubFolder
of your App).

The Demo here tries to show not only how to create the STA-threads with a Class-
Instance in it, but also how to share Memory with the Applications Main-Thread
(which is the fastest way of cross-thread-communication).

The implementation of the Main-App is using a separate (Private) Wrapper-Class
for handling the "Remote-Thread" (offering Properties to wrap the shared Memory-area,
and such a Class will also automatically close the thread it wraps, in case it is itself terminated).

That allows for cleaner Code in the "Thread-consuming-instance" (in our case the Apps fMain-Form).

The Code for the ThreadLib.dll on the other hand - (this is the AX-Dll which provides a Public
cThread-Class, which will finally run on its own threaded Apartment) - is contained in the
\Bin\... SubFolder of the Zip.

Just leave this Bin-SubFolder as it is, when you run the Main-Apps *.vbp File.

Here's the Code for the Demo:
VB6ThreadingDirectCOM.zip

And here is a ScreenShot (the colored Forms are created inside the 4 Threads - and perform
an endless loop, to show some kind of "Plasma-Effect" - just to put the threads under stress a bit).



Have fun (and just ask when you have any questions - though I tried to comment the Demo well enough, I hope).

Olaf
Attached Files

Viewing all articles
Browse latest Browse all 1530

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>