Solved

Creating a Thread

Posted on 2000-03-17
6
264 Views
Last Modified: 2010-05-02
How can i create a thread?My aim is to create a thread and i would pass a query in that. This query should run on the Server and should return the results to Client.
0
Comment
Question by:v_senthil75
6 Comments
 
LVL 3

Accepted Solution

by:
Redlord earned 50 total points
ID: 2627647
Public Declare Function CreateThread Lib "kernel32" Alias "CreateThread" (lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long

MSDN "CreateThread":
lpThreadAttributes
Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited.
Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new thread. If lpThreadAttributes is NULL, the thread gets a default security descriptor.

dwStackSize
Specifies the initial commit size of the stack, in bytes. The system rounds this value to the nearest page. If this value is zero, or is smaller than the default commit size, the default is to use the same size as the calling thread. For more information, see Thread Stack Size.
lpStartAddress
Pointer to the application-defined function of type LPTHREAD_START_ROUTINE to be executed by the thread and represents the starting address of the thread. For more information on the thread function, see ThreadProc.
lpParameter
Specifies a single 32-bit parameter value passed to the thread.
dwCreationFlags
Specifies additional flags that control the creation of the thread. If the CREATE_SUSPENDED flag is specified, the thread is created in a suspended state, and will not run until the ResumeThread function is called. If this value is zero, the thread runs immediately after creation. At this time, no other values are supported.
lpThreadId
Pointer to a 32-bit variable that receives the thread identifier.
Windows NT: If this parameter is NULL, the thread identifier is not returned.

Windows 95 and Windows 98: This parameter may not be NULL


check out: http://216.5.163.42/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=4823

for a good sample app
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2627718
If you use ADODB, then simply to Connection.Execute ("QUERY", , adAsyncExecute) and find the Recordset in the ExecuteComplete Event of the connection Object
0
 
LVL 18

Expert Comment

by:mdougan
ID: 2627946
Be aware that Microsoft does not support the CreateThread API for VB 6.  It does work fine in VB 5, but you may have trouble if you try to use it in VB 6.  I have a sample that uses it, which I will send if you post an e-mail address, but you should only do this if you are using VB 5 (or just want to see the code).

Another note, when you are debugging a program that uses threads, you should never try to run in the debugger.  It will cause VB to GPF.  You should always compile to an EXE and then test the EXE.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:Redlord
ID: 2628072
mdougan: i am using VB6 and the sample that i posted a link to works fine for me
0
 

Author Comment

by:v_senthil75
ID: 2631023
Creating Thread is ok.
How can i pass a query in that to the server and get the result back in the client.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 2631844
I haven't had a chance to look at your example yet, but I didn't say that you couldn't use VB6 with CreateThread, just that Microsoft has changed the implementation of the threading model of VB with VB 6, and there are now major restrictions with using the CreateThread API. And, they officially say that they don't support the use of this API with VB 6 (which means they don't want to get any support calls if your programs keep blowing up)

Here is the link that describes the restrictions:

http://support.microsoft.com/support/kb/articles/q198/6/07.asp

If you read this KB article, there is also a link to an article by Dan Appleman which explains a lot of how Threads work in VB.  The major limitation now is in the use of Callback functions.  If you were to spawn threads that ran their course and just ended, then I don't think you will have a problem.  However, if you want the thread to do something, then callback to the program when finished, or to return something, then you may have trouble.

Now, that said, I saw an article in the VB Programmers Journal back in October or November that was on creating threads in VB 6 in a completely different way.  This would be worth researching.  
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now