The VB itself does not support multi-threaded. However, the components in VB have the distinction between the processes and processes, so I use process external parts to achieve asynchronous calls. Server-side code, create a new ActiveExe project, add a form, and store a Timer control to add a class module. Code The following private withevents m_timer as Timerpublic Event MyTaskResult (Result As Long) Private J $ longprivate sub class_initialize () set m_timer = form1.timer1end SUB
PRIVATE SUB M_TIMER_TIMER () m_timer.enabled = false Dim i as long Dim R as long for i = 0 to j r = r i Next RaiseEvent MyTaskResult (r) end sub
Public Sub MyBigTask (i As Long) m_Timer.Enabled = True m_Timer.Interval = 10 j = iEnd Sub client Private WithEvents longTask As AsyncServerTest.MyAsyncClsPrivate Sub Command1_Click () Set longTask = New AsyncServerTest.MyAsyncCls longTask.MyBigTask (Text1.Text) End Sub
PRIVATE SUB Longtask_mytaskResult (Result As Long) Text2.text = Result MsgBox "long task finished" end sub