2

I made this simple html application using vbscript.

<html>
  <head>
    <title>Example</title>
<script type="text/vbscript" src="scr1.vbs"></script>
<script type="text/vbscript" src="scr2.vbs"></script>
  </head>
  <body>
    <p>Example</P>
    <button onClick="scr1">scr1</button>
    <button onClick="Scr2()">scr1</button>
    </body>
</html>

Now script1 and 2 both takes lot of time to complete. While one of the script is running the application hangs. Is there any way I can do it async.

vbscripts are similar to this.

Set fso = CreateObject("Scripting.FileSystemObject")
For Each oFile In fso.GetFolder(sFolder).Files
  If LCase(fso.GetExtensionName(oFile.Name)) = "txt" Then 
    set oFile = fso.OpenTextFile(oFile)
        Do While oFile.AtEndOfStream <> True
            TextLine = TextLine & oFile.ReadAll
        Loop
  End if
Next

Set regEx_ = new regExp
With regEx_
    .Global = True
    .MultiLine = True
    .IgnoreCase = True
    .Pattern = "pattern 1"
    TextLine = regEx_.replace(TextLine, "mmrk$&")
    .Pattern = "pattern 2"
    TextLine = regEx_.replace(TextLine, "mmrk$&")
    'and 100 more such complex regex replaces
End With

set Temp = fso.CreateTextFile(TempFile, True)
    Temp.Write TextLine
    Temp.Close
Set Temp = Nothing

Is there any scope here also to make it async?

Rahul
  • 10,830
  • 4
  • 53
  • 88
  • Are you locked in with the vbscript? Or can you use JavaScript? – Maksim Luzik Apr 05 '16 at 07:12
  • 1
    You need to use JavaScript with [webworkers](http://stackoverflow.com/questions/18894830/how-to-run-javascript-function-in-background-without-freezing-ui) (possible duplicate). – Quentin Apr 05 '16 at 07:14
  • right now I am locked with vbscript as it is using the file system object. I don't know how to use jscript. I am thinking of learning. – Rahul Apr 05 '16 at 07:29
  • 2
    Unfortenately Webworkers seem not having the same privileges as HTAs. Instead you can run the long-polling part in a separate HTA-window or use a WSF (can be written with VBS too) file. In both cases, when the job will be done, write the results in a single file. To the main HTA, you've to create a checking function which is run for ex. once per second, and checks, if the response file exists. When the file is found, just read it with FSO, and the delete the file. – Teemu Apr 05 '16 at 10:39
  • it's gonna take a while for understanding your instruction. I will update. – Rahul Apr 05 '16 at 10:42
  • If you run the VBScript through the `wscript host exe`, it will not interfere with `mshta.exe` 's process. – Aaron Gillion Apr 06 '16 at 02:12

1 Answers1

0

To run scripts async you need this the async specified in the script:

<script src="demo_async.js" async></script> 

Here is some info upon this subject : https://css-tricks.com/async-attribute-scripts-bottom/

  • let me test if it's true for vbscript+HTA too – Rahul Apr 05 '16 at 07:36
  • If you use the `async` attribute, you are saying: I don't want the browser to stop what it's doing while it's downloading this script but do not prevent browser freezing when it's running. – Rahul Apr 05 '16 at 07:46
  • Move the position of the scripts . Put one on the bottom of the page . While in the head the scripts load before the page loads. Put them on the bottom of the page . There is also the defer script tag which tells the script to load after the page has finished parsing . – Dragutescu Alexandru Apr 05 '16 at 07:58