[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

Creating a Thread

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
v_senthil75
Asked:
v_senthil75
1 Solution
 
RedlordCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
If you use ADODB, then simply to Connection.Execute ("QUERY", , adAsyncExecute) and find the Recordset in the ExecuteComplete Event of the connection Object
0
 
mdouganCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
RedlordCommented:
mdougan: i am using VB6 and the sample that i posted a link to works fine for me
0
 
v_senthil75Author Commented:
Creating Thread is ok.
How can i pass a query in that to the server and get the result back in the client.
0
 
mdouganCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now