Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a thread in vb 6 1

Status
Not open for further replies.

darkman0101

Technical User
Oct 10, 2000
51
NZ
Ok.. who wants to let me in on a secret?
I have an application that uses the Crystal Report Control.
If the user hits the Cancel button on the parameter form for the report once CrystalReport.action = 1 is set the report runs anyway, (and depending on the report this can take a while).

What I want to do is run this in another thread so the user can kill it and not kill the main app.

I understand that VB 6 does not support createthread()...
So what's the answer?
 
darkman0101,
You are right! VB6 does not support CreateThread . . . it will GPF almost every time. VB5 did but it was just a fluke and MS "fixed" that problem. the only threading model available in VB6 is apartment threading. This fall, when VB.net comes out, you will have the ability to create free threads with normal code (no APIs).
Until then, probably your best bet is to write an ActiveX EXE (this will create another process) and then have the report run in the new process. If the user kills the process there (actually, you should give them a way to politely exit . . . not kill) control will return to the original process.
By creating the new process, you effectivly are creating a new thread, but you also have to deal with inter-process communications which can get ugly.
- Jeff Marler
(please note, that the page is under construction)
 
Jeff's right. Multi-processing is the way to go here. I get away with launching standard .exe's (using SHELL) from a single CONTROL Application. This Control application communicates with the 'child' processes using a method called 'File Mapping' (Otherwise known as Shared Memory). The launched child programs sit in a standby mode, polling for new commands using a Timer control (okay, so perhaps the Timer Control is not the most elegant solution - but hey IT WORKS!). The child programs essentially poll memory spaces, which act like 'Windows-wide global variables', and can therefore be seen by other programs who make reference to this 'shared memory' in their code.

A good place to look for this info is Dan Appleman's : Visual Basic Programmer's Guide to the Win32 API book, in the 'Processes and Threads' chapter. This chapter introduces you to Shared Memory, Mutexes, Anonymous and Named Pipes (yuk! Avoid pipes if you can!)...

Short of it is that you'll have to create class modules for Shared Memory, Pipes or Mutexes using Win32 API calls. We already have these objects done where I work, but I unfortunately cannot distribute the code thanks to stringent corporate regulations! UGH!

Hope this helps! + Good Luck!

Thanks!
LeGo PiEcE

"The Computer Spock! Destroy it!" - Captain James T. Kirk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top