I have made a breakthrough! I found a wonderful FREE object called
COMScriptThread. It allows you to run functions and or entire scripts asynchronously! This is unbelievably useful for processing log files at high speed where you need to stop and start actions very quickly. You can download it
here.
It's use took me a couple hours to figure out as the documentation isn't stellar. But it's free so who cares! Below I am posting example code so you will not have to fight with it like I did.
Main code:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
'main.vbs
Option Explicit
Dim thread, XX, ThreadFile, sf
Set thread = CreateObject("newObjects.utilctls.COMScriptThread")
Set sf = CreateObject("newObjects.utilctls.SFMain") 'Like FSO but more flexible
Set ThreadFile = sf.OpenFile("test.vbs")
If thread.Start("VBScript",ThreadFile.ReadText(-2)) Then
If thread.Wait(30000) then 'Waiting up to 30 seconds - not necessarily required for this example
If thread.success Then 'The thread started!
thread.Execute("Tester") 'Execute the subroutine Tester from test.vbs
MsgBox("Success")
Else
thread.Stop
XX = thread.LastError 'Something went wrong waiting for the thread to start
MsgBox(XX) 'Let's see what it was
End If
Else
XX = thread.LastError 'The thread would not start at all if we got here.
MsgBox(XX) 'Let's see why?
End If
End If
Code we use to generate threads:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
'test.vbs
Option Explicit
Dim objFSO, objFSOText, objFolder, objFile
Dim strDirectory, strFile, strFile1
strDirectory = "c:\Scripts"
strFile = "\Special.txt"
strFile1 = "\Special1.txt"
Sub Tester
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
Echo "Just created " & strDirectory & strFile
End Sub
Sub Tester1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strDirectory & strFile1)
Echo "Just created " & strDirectory & strFile1
End Sub
It's a very simple example and I am not actually doing anything asynchronously, though I could be. I am simply demonstrating use of the members.
The Tester & Tester1 subroutines could be looped doing quite a bit of work if this script actually did anything useful. If that were the case, with this code I would have the power to start and stop either one at will.
One thing I have noticed is that there doesn't seem to be a way to stop routines that you have executing asynchronously in the same thread individually. You cannot stop someting you executed. Stop kills the entire thread. If you need that ability (as I do) just execute your subs using seperate threads (IE load the vbs file several times with a different thread name) or just split the subs that need that ability into different files (more effecient).