In my HTA app there are some actions which are executing some heavily time-consuming tasks on a server. For example an action uses an old ActiveX component to read some fileproperties (like Subject and Comments) of files in a particular folder (0 - ~200 files in a folder).
Originally this was done by setting an interval, and reading the fileproperties file by file. The slowing down of the app was acceptable when connected to the server using fast local connections. But now, as remote working has significantly increased, and the remote connections are magnitudes slower than the intranet connections, the interval is not suitable for the task anymore.
To make the app faster during the filepropety search, I outsourced the code to a wsh job. The results are stored in a file, which of existence an interval (5 secs) is observing. However, some users are still experiencing remarkable slow-down of the app, even when polling the file existence with the said interval of 5 secs.
Now I wanted to know, if there is an event or some other internal mechanism, which I could use to detect when the wsh script has done its job? And if possible, even perhaps there's a way to send the results directly from the wsh job to HTA, without using the intermediate temporal file at all?
Here's some simplified code for the actual task performed in the wsh file and HTA app. HTA has the HTML5 DTD and it's running in Edge-mode using IE11. ui is an utility library, the referred propertynames are hopefully describing the usage accurate enough.
WSF:
<package>
<job id="getFileProps">
<script language="JScript">
(function () {
var topRoot = WScript.Arguments(0), // The starting folder <String>
fso = WScript.CreateObject('Scripting.FileSystemObject'), // Filesystem object <ActiveXObject>
fileProps = readProps(topRoot), // Fileprops, the result <Array>
file; // The result file to read in HTA <FileObject>
function readProps (root) {
var fileProperties = [];
// A bunch of code reading the fileproperties on a disk
return fileProperties;
}
file = fso.openTextFile(topRoot + '\\$fileprops$.txt', 2, true);
file.Write(fileProps.join(',');
file.Close();
WScript.Quit();
)());
</script>
</job>
</package>
JSCRIPT:
ui.winShell.Exec('WScript //Job:getFileProps ' + '"' + ui.appRoot + '"');
function fpCheck () {
var file, fileProps;
try {
file = ui.fileIO.OpenTextFile('$fileprops$.txt', 1, false);
} catch (err) {
file && file.Close();
setTimeout(fpCheck, 5000);
return;
}
// Write the fileprops to the view
}
If someone is interested in the fileproperty reader, its name is DSOFile.OleDocumentProperties. It originates somewhere to the deep internet archives, but I can't recall where I've loaded it from.