Solved

Creating a Thread

Posted on 2000-03-17
6
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 143

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

749 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