VB6 Threads, easy solution
Author |
Message |
brendo #1 / 24
|
 VB6 Threads, easy solution
VB6 Threads, easy solution I am in the process of writing a file creation test harness and experiencing problems with the program locking up when creating large files. And would like to use VB multi-thread capability to over come this problem. I have done a lot of reading on the subject and became very confused very quickly. I understand VB6 has the ability to use the active X class files to handle the threads, but what I am having problems with is how to start them using a thread. May be I am completely missing the point, but what is the best way to create threads in VB6 Or multi-tasking ? Ideally I am looking for an easy example within VB6 of multi-threads, Any ideas are welcome to stop my little brain from hurting. Thanks in advance Regards Brendon Shaw
|
Wed, 08 Sep 2004 03:05:16 GMT |
|
 |
dsavits #2 / 24
|
 VB6 Threads, easy solution
I have found that writing COM objects in other languages that can spawn threads easily and creating them via CreateObject('COM.Object', 'Server') is a good solution. i have no clue how to do it purely in VB though. -d
Quote: > VB6 Threads, easy solution > I am in the process of writing a file creation test harness and experiencing > problems with the program locking up when creating large files. And would > like to use VB multi-thread capability to over come this problem. I have > done a lot of reading on the subject and became very confused very quickly. > I understand VB6 has the ability to use the active X class files to handle > the threads, but what I am having problems with is how to start them using a > thread. May be I am completely missing the point, but what is the best way > to create threads in VB6 Or multi-tasking ? > Ideally I am looking for an easy example within VB6 of multi-threads, > Any ideas are welcome to stop my little brain from hurting. > Thanks in advance > Regards > Brendon Shaw
|
Wed, 08 Sep 2004 03:48:25 GMT |
|
 |
dsavits #3 / 24
|
 VB6 Threads, easy solution
Quote: > i have no clue how to do it purely in VB though.
... but see "call com component and not wait for execution" below for someone who does :-) -d
|
Wed, 08 Sep 2004 03:51:58 GMT |
|
 |
J Fren #4 / 24
|
 VB6 Threads, easy solution
VB6 is not multi-threaded You can (if you are crafty) delegate tasks to other Apps' Threads ie: kick of an AX EXE or ... simply just another App On Fri, 22 Mar 2002 19:05:16 +0000 (UTC), "brendon" Quote:
>VB6 Threads, easy solution >I am in the process of writing a file creation test harness and experiencing >problems with the program locking up when creating large files. And would >like to use VB multi-thread capability to over come this problem. I have >done a lot of reading on the subject and became very confused very quickly. >I understand VB6 has the ability to use the active X class files to handle >the threads, but what I am having problems with is how to start them using a >thread. May be I am completely missing the point, but what is the best way >to create threads in VB6 Or multi-tasking ? > Ideally I am looking for an easy example within VB6 of multi-threads, > Any ideas are welcome to stop my little brain from hurting. >Thanks in advance >Regards >Brendon Shaw
|
Wed, 08 Sep 2004 04:23:03 GMT |
|
 |
Tom Shelto #5 / 24
|
 VB6 Threads, easy solution
Quote: > VB6 Threads, easy solution > I am in the process of writing a file creation test harness and experiencing > problems with the program locking up when creating large files. And would > like to use VB multi-thread capability to over come this problem. I have > done a lot of reading on the subject and became very confused very quickly. > I understand VB6 has the ability to use the active X class files to handle > the threads, but what I am having problems with is how to start them using a > thread. May be I am completely missing the point, but what is the best way > to create threads in VB6 Or multi-tasking ? > Ideally I am looking for an easy example within VB6 of multi-threads, > Any ideas are welcome to stop my little brain from hurting.
Use an ActiveX exe with the thread pool set to thread per object. Then every time a request is made, the server spins the object out on it's own thread. To make calls to the object asyncronous, you'll want to use a timer (one easy way to do this is to use the SetTimer API to handle the call back, or you can look at the ccrp timer stuff, this allows you to avoid the overhead of a form.). Here is a simple example using the ccrpTimer: Option Explicit Implements ICcrpTimerNotify Private mTmr As ccrpTimer Private mData As String Public Event AllDone(data As String) Private Sub Class_Initialize() Set mTmr = New ccrpTimer With mTmr Set .Notify = Me .Interval = 100 .EventType = TimerOneShot End With End Sub Public Sub DoIt(data As String) mData = data mTmr.Enabled = True End Sub Private Sub ICcrpTimerNotify_Timer(ByVal Milliseconds As Long) ' DO YOUR INCREDABLY LONG METHOD HERE RaiseEvent AllDone(mData) End Sub Then, your client can reference the AX Exe, and do something like: Private WithEvents ao As AsyncObject Private Sub Command1_Click() command1.enabled = false set ao = new AsyncObject ao.DoIt(sMyData) ' returns immediately so the user is free to continue performing other actions on the user interface. End Sub ' Fires when the data is done processing Private Sub ao_AllDone(data As String) msgbox data command1.enabled = true End Sub There is the Coffee Example that comes with VB6. It shows how to do this using the SetTimer API. By the way, the ccrpTimer stuff is great, it can be downloaded from http://www.mvps.org/ccrp/ HTH, Tom Shelton
|
Wed, 08 Sep 2004 05:53:51 GMT |
|
 |
Edward G. Nilg #6 / 24
|
 VB6 Threads, easy solution
Quote:
> VB6 Threads, easy solution > I am in the process of writing a file creation test harness and experiencing > problems with the program locking up when creating large files. And would > like to use VB multi-thread capability to over come this problem. I have > done a lot of reading on the subject and became very confused very quickly. > I understand VB6 has the ability to use the active X class files to handle > the threads, but what I am having problems with is how to start them using a > thread. May be I am completely missing the point, but what is the best way > to create threads in VB6 Or multi-tasking ?
Some suggestions: (1) Don't use VB6, use VB.Net if possible. VB.Net is available as part of Visual Studio .Net and it completely supports threads. VB-6 only painfully supported threads. (2) If (1) is not possible consider making the file create windowless with a Sub Main, and then use the VB-6 Shell command to run this. This will give you a simple, legacy, MS-DOS based form of tasking since you can wait until the task ID (returned by Shell if memory serves) is complete. For true independence of operating systems considerations, consider having the shelled application write one extra, one line file, with a unique name such as ~IamDone~.TXT. Then, when the main program wants to check to see if the file is done, it can check for the existence of this file. (3) Or, consider taking another look at the file create. Perhaps it can be made more efficient, which will avoid the (very serious) issues that arise in multiple threads even when your platform truly supports threads (which VB-6 does not.) If the file create is writing line by line, consider using binary, character mode output. Consider that multi-threading by itself will not necessarily make your code more efficient. After all, you usually only have one processor to work with. Since you are creating a file, CPU time is not the issue, instead, the overhead of writing a line at a time may be an issue. I find that blasting the entire file in terms of characters is both more unix-like (meaning conceptually clearer) and more efficient than line at a time output, which subconsciously replicates an outdated IBM "unit record" ideology. Quote: > Ideally I am looking for an easy example within VB6 of multi-threads, > Any ideas are welcome to stop my little brain from hurting. > Thanks in advance > Regards > Brendon Shaw
|
Wed, 08 Sep 2004 07:16:45 GMT |
|
 |
dsavits #7 / 24
|
 VB6 Threads, easy solution
Quote: > > VB6 Threads, easy solution > > I am in the process of writing a file creation test harness and experiencing > > problems with the program locking up when creating large files.
<snip> Quote: > > what is the best way > > to create threads in VB6 Or multi-tasking ? > Some suggestions:
<snip> Quote: > (2) If (1) is not possible consider making the file create windowless > with a Sub Main, and then use the VB-6 Shell command to run this. > This will give you a simple, legacy, MS-DOS based form of tasking > since you can wait until the task ID (returned by Shell if memory > serves) is complete. For true independence of operating systems > considerations, consider having the shelled application write one > extra, one line file, with a unique name such as ~IamDone~.TXT. Then, > when the main program wants to check to see if the file is done, it > can check for the existence of this file.
This sounds like a job more for a named pipe than for a text file. here's how to do it in vb ... http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q17769... Quote: > Consider that multi-threading by itself will not necessarily make your > code more efficient. After all, you usually only have one processor > to work with. Since you are creating a file, CPU time is not the > issue, instead, the overhead of writing a line at a time may be an > issue.
it doesn't necessarilly sound like efficiency is the issue either, but more like the file creation should be done elsewhere. the biggest problem w/ threads for this is that if the main thread (the application) is closed it will likely take down the worker threads with it. perhaps the best solution is a service that continually checks a named pipe for instructions. it can report back to the pipe when it is done. this is quick enough that it will seem more or less like the applications are directly talking, but they will still maintain independence from one another. -d
|
Wed, 08 Sep 2004 07:59:48 GMT |
|
 |
Joe #8 / 24
|
 VB6 Threads, easy solution
Quote:
> VB6 Threads, easy solution > I am in the process of writing a file creation test harness and experiencing > problems with the program locking up when creating large files. And would > like to use VB multi-thread capability to over come this problem. I have > done a lot of reading on the subject and became very confused very quickly. > I understand VB6 has the ability to use the active X class files to handle > the threads, but what I am having problems with is how to start them using a > thread. May be I am completely missing the point, but what is the best way > to create threads in VB6 Or multi-tasking ? > Ideally I am looking for an easy example within VB6 of multi-threads,
Don't listen to those Zany Imbeciles who'll try to tell you that you must use VB.NET or resort to Shell to achieve multithreading in VB: URL:http://groups.google.com/groups?selm=e0yo%23nouBHA.360%40tkmsftngp07 Quote: > Any ideas are welcome to stop my little brain from hurting.
You might not even need threading at all. Could you pop your file creation code into a private class module and call RaiseEvent every so often? That way, your GUI logic could have control over whether it updates a progress meter, calls DoEvents, or what have you. -- Joe Foster <mailto:jlfoster%40znet.com> Space Cooties! <http://www.xenu.net/> WARNING: I cannot be held responsible for the above They're coming to because my cats have apparently learned to type. take me away, ha ha!
|
Wed, 08 Sep 2004 08:43:54 GMT |
|
 |
Michael Carto #9 / 24
|
 VB6 Threads, easy solution
Quote:
> VB6 Threads, easy solution > I am in the process of writing a file creation test harness and experiencing > problems with the program locking up when creating large files. And would > like to use VB multi-thread capability to over come this problem. I have > done a lot of reading on the subject and became very confused very quickly. > I understand VB6 has the ability to use the active X class files to handle > the threads, but what I am having problems with is how to start them using a > thread. May be I am completely missing the point, but what is the best way > to create threads in VB6 Or multi-tasking ? > Ideally I am looking for an easy example within VB6 of multi-threads,
Unless you're running the program on a multi-CPU machine and/or multi-disk controller machine, you're not going to gain any speed advantage in creating large files. (You ARE creating them on local disks, right?) -- MikeC Please reply to the group.
|
Wed, 08 Sep 2004 12:57:04 GMT |
|
 |
Edward G. Nilg #10 / 24
|
 VB6 Threads, easy solution
Quote:
> > VB6 Threads, easy solution > > I am in the process of writing a file creation test harness and experiencing > > problems with the program locking up when creating large files. And would > > like to use VB multi-thread capability to over come this problem. I have > > done a lot of reading on the subject and became very confused very quickly. > > I understand VB6 has the ability to use the active X class files to handle > > the threads, but what I am having problems with is how to start them using a > > thread. May be I am completely missing the point, but what is the best way > > to create threads in VB6 Or multi-tasking ? > > Ideally I am looking for an easy example within VB6 of multi-threads, > Don't listen to those Zany Imbeciles who'll try to tell you that you > must use VB.NET or resort to Shell to achieve multithreading in VB: > URL:http://groups.google.com/groups?selm=e0yo%23nouBHA.360%40tkmsftngp07
Hey, Bubba, even the documentation itself declares that the method is a kludge. Multiprocessing should not be used in VB-6 for even when it is cleaned up in VB.Net it presents problems beyond the abilities of your software maintainers even if you, Bubba, are able to understand the issue. As ever, I remain, the Zany Imbecile, Edward G. Nilges
|
Thu, 09 Sep 2004 07:46:51 GMT |
|
 |
Tom Shelto #11 / 24
|
 VB6 Threads, easy solution
Quote: > Hey, Bubba, even the documentation itself declares that the method is > a kludge. Multiprocessing should not be used in VB-6 for even when it > is cleaned up in VB.Net it presents problems beyond the abilities of > your software maintainers even if you, Bubba, are able to understand > the issue.
Why? VB 6 is multithreaded. It just isn't FREE threaded - different issue. I already responed to this question with a simple example of how this can be accomplished. You just need to put it into an ActiveX exe with the threading modle set to thread per object. Then every time a client creates a new object, walla - new thread. The problems come in when you need to share data accross multiple threads since all data is initialized per thread - there is no sharing. There are hacks around this, but for many, many problems this is not an issue. You should go buy Mat Curlands Advanced VB6 book, it would make your head spin. Tom Shelton
|
Thu, 09 Sep 2004 13:43:17 GMT |
|
 |
Edward G. Nilg #12 / 24
|
 VB6 Threads, easy solution
Quote:
> > Hey, Bubba, even the documentation itself declares that the method is > > a kludge. Multiprocessing should not be used in VB-6 for even when it > > is cleaned up in VB.Net it presents problems beyond the abilities of > > your software maintainers even if you, Bubba, are able to understand > > the issue. > Why? VB 6 is multithreaded. It just isn't FREE threaded - different issue. > I already responed to this question with a simple example of how this can > be accomplished. You just need to put it into an ActiveX exe with the > threading modle set to thread per object. Then every time a client creates > a new object, walla - new thread. The problems come in when you need to > share data accross multiple threads since all data is initialized per > thread - there is no sharing. There are hacks around this, but for many, > many problems this is not an issue. You should go buy Mat Curlands Advanced > VB6 book, it would make your head spin. > Tom Shelton
Thanks for the suggestion, Tom. But I am not convinced of the value of multithreading on the desk-top since even Microsoft says that multithreading only increases availability without, in most cases, increasing efficiency. Wanting to multithread when one's code is slow is a programmer's form of the manager's fallacy. Many managers want to "solve" the problem of slow code by buying bigger CPUs. Many programmers think that multithreading is a magic bullet. Most business problems could stand better algorithm design in place of multithreading, for example, the use of keyed collections in place of linear search (or some clown's triumphant but incorrect version of the binary search.)
|
Fri, 10 Sep 2004 05:08:40 GMT |
|
 |
Joe #13 / 24
|
 VB6 Threads, easy solution
[Edward the Imbecile gabbles:] Quote: > > Hey, Bubba, even the documentation itself declares that the method is > > a kludge. Multiprocessing should not be used in VB-6 for even when it > > is cleaned up in VB.Net it presents problems beyond the abilities of
Yup, having to pass around AddressOf's willy-nilly is certainly my idea of "cleaned up" multiprocessing... .NOT! Quote: > > your software maintainers even if you, Bubba, are able to understand > > the issue. > Why? VB 6 is multithreaded. It just isn't FREE threaded - different issue. > I already responed to this question with a simple example of how this can > be accomplished. You just need to put it into an ActiveX exe with the > threading modle set to thread per object. Then every time a client creates > a new object, walla - new thread. The problems come in when you need to > share data accross multiple threads since all data is initialized per > thread - there is no sharing. There are hacks around this, but for many, > many problems this is not an issue.
What's so horrible about another (single-threaded) ActiveX EXE or passing around an object reference to hold the shared data? True, you'll get the cross-apartment marshaling perf hit up the wazoo, but that's usually faster than tracking down "the last" threading synchronization mandelbug before you can release your program... Quote: > You should go buy Mat Curlands Advanced > VB6 book, it would make your head spin.
I think Edward's head has been spinning ever since he first tried to impersonate a computer programmer. -- Joe Foster <mailto:jlfoster%40znet.com> Space Cooties! <http://www.xenu.net/> WARNING: I cannot be held responsible for the above They're coming to because my cats have apparently learned to type. take me away, ha ha!
|
Fri, 10 Sep 2004 05:14:08 GMT |
|
 |
Joe #14 / 24
|
 VB6 Threads, easy solution
Quote:
> > VB6 Threads, easy solution > > I am in the process of writing a file creation test harness and experiencing > > problems with the program locking up when creating large files. And would > Unless you're running the program on a multi-CPU machine and/or multi-disk > controller machine, you're not going to gain any speed advantage in creating > large files. (You ARE creating them on local disks, right?)
I haven't seen much benefit from multiple CPUs when using multithreading to write or copy large files, but I have when using just a single CPU with multiple SCSI drives, even with a single single-channel controller, so long as no two threads are hitting the same drive at the same time. (Unless your OS' disk caching is better than mine!) -- Joe Foster <mailto:jlfoster%40znet.com> Sign the Check! <http://www.xenu.net/> WARNING: I cannot be held responsible for the above They're coming to because my cats have apparently learned to type. take me away, ha ha!
|
Fri, 10 Sep 2004 05:22:59 GMT |
|
|
Page 1 of 2
|
[ 24 post ] |
|
Go to page:
[1]
[2] |
|