将下面的语句可作为一个线程用吗?
Public Sub AsyncThread()
Dim rs As New ADODB.Recordset
Dim str As String
str = "Provider=sqloledb;Data Source=tt;Initial Catalog=tt;uid=sa;pwd=sa;"
rs.Open "select * from tab", str
Set Form1.FGrid.Recordset = rs
End Sub
...全文
6413打赏收藏
可以用多线程吗?
将下面的语句可作为一个线程用吗? Public Sub AsyncThread() Dim rs As New ADODB.Recordset Dim str As String str = "Provider=sqloledb;Data Source=tt;Initial Catalog=tt;uid=sa;pwd=sa;" rs.Open "select * from tab", str Set Form1.FGrid.Recordset = rs End Sub
你可以使用ado的异步记录集
用withevens声明你的recordset对象
dim wthevents rs As ADODB.Recordset
这样就可以编写recordset的事件代码
打开时用adAsyncExecute选项
rs.Open "select * from tab",cn,adopenstatic,adoptimistic,adAsyncExecute
当查询完成会触发executecomplete事件
新建一Module
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Sub main()
Load Form1
Form1.Show
End Sub
Public Sub c1()
.......
End Sub
Public Sub c2()
......
End Sub
新建一窗体
Private hthread1 As Long
Private hthread2 As Long
Private ithread1 As Long
Private ithread2 As Long