10-03-2001, 07:04 AM
Here is an old issue where I just can't get any response to it. I have an MDIForm and it contains two types of MDIChild forms, indexed. That means that you can have two occurences of the MDIChild1 and three occurences of the MDIChild2 at the same time. My problem is about threading. I would like my program to be able to process some stuff on two form at the same time. Suppose that one form is currently working on executing a queyr, I would like the user to be able to call another query while the other one is executing...It has everything to do with threading, but I am dealing with the unknown here :(
10-03-2001, 07:12 AM
there's two thing you need to note in this situation:
1- even if you do multi threading, you'll only decrease the speed of the execution of all the querys
2- if you don't have a multiprocessor computer it can only execute one thing at the time (one then the other...)
I'll be amongst the best any minute now !
10-03-2001, 07:25 AM
I have some program around that can easily execute two queries at the time...
My point is how can I handle two running procedures at the same time ?
10-03-2001, 08:05 AM
If the query is being handled by an outside function (API or MS Office product) then you'll need to see if that function you are using supports callbacks.
If it is you're own routine then put a DoEvents in there somewhere.
10-03-2001, 05:06 PM
I'm currently writing a very long tutorial on threading in Visual Basic.
It should be out in a month (Yes, I know, long time away, but I do have another life).
Back to the problem though.
The CreateThread API function doesn't work well in Visual Basic because when you create a new thread it can't access the Visual Basic Runtime .dll and therefore crashes the program if a call is made to the runtime.
Even a For/Next statement requires the runtime.
Keep in mind though that if what you want to do can be coded without using the runtime (declare variables, loops, API) then CreateThread will in fact work for you.
Although in most cases you're going to wind up with a nice error message about an invalid memory address on your screen.
So here's what it boils down to:
1. Try DoEvents (ugh)
2. Use an ActiveX EXE
3. Create a passing function that passes control from one window to another (sharing in other words)
4. Wait for my tutorial
02-27-2002, 04:36 PM
I just wondering if you've finished with your new multi-threading tutorial, 'cause I'm interested to find out how to implement it properly on VB apps.
02-27-2002, 05:06 PM
I think that it is not How to handle multithread execution,
but it is what and how you want to handle them.
02-27-2002, 05:54 PM
I want to run 2 processes at the same time.
Process 1: Fetching the attributes from the server
Process 2: Fetching the coordinates from the server
My question is, while process 2 still running,
does that mean the user waits until all the coors are fetched
before continuing, or can they continue working on other functionality while the coors download?
02-28-2002, 07:06 PM
Anyone out there has an idea to my question?
03-01-2002, 01:50 AM
Are you using ADO to get data from the server?
If so, you could start your query in asynchronous(?) mode and use the Events() generated by the recordsets. Your code will continue and not wait until the query has finished.
03-03-2002, 06:52 PM
Thanks for your response.
I actually send the request command via httpd to the server.
The scenario is:
I send a request for queries via httpd to the server and
the server sends back the data to the client, BUT at the same time, I needed to send another request for the features via httpd to the server (ie. running on the background).
Therefore, while the client starts downloading the features, can a user continue working on other functionality on the client machine?
03-03-2002, 07:44 PM
It does not matter Yes or No answer, for it has less meaning
than the result from your actual work, that requires much work.
Please, just start on your plan, and bring any problems you
encounter. This helps all of us.
03-03-2002, 09:47 PM
My application works perfectly!! but I'm just thinking of implementing some sort like multi threads, but before I move on
any further I want to find out if that can be achieved!
Currently, it sends a request to the server one at a time,
something like this:
'' Send the request for queries
bRet = HttpSendRequest(hHttpOpenRequest, vbNullString, 0, sPostCommand, Len(sPostCommand))
'' Now loop around and retrieve the data
bDoLoop = True
lNumberOfBytesRead = 0
While bDoLoop <> 0
bDoLoop = InternetReadFile(hHttpOpenRequest,
sBuffer = sBuffer & Left(sReadBuffer,
If Not CBool(lNumberOfBytesRead) Then _
bDoLoop = False
''Now populate the queries data onto a table (ie. MSFlexgrid) to be displayed on the screen
While the data is being populated, I want to send another request to the server to fetch the features, at the same time
the user still able to do another functionality (ie. move a mouse,
zoom in etc...)
03-04-2002, 07:45 AM
It makes sense, but multi-threading in VB is so incredibly complex
that you would spend weeks making it work even if you already
completely understood the concept. One reason is the worker
threads you create do not have access to variables/functions of
the main thread. You have to pass all info in storage structures,
and the worker thread is on its own, doing only what is available
in its own code. Even returning values is a pain.
03-04-2002, 09:41 AM
If it were so easy to use multithreading then the hourglass mouse cursor would be obselete. However, we all know that it isnt.
03-04-2002, 09:52 AM
Even then, it will only be obsolete when we all have PCs that
have as many processors as active threads.
03-04-2002, 03:22 PM
Thanks guys for your reply.