Detecting halt requests

function HaltSignalReceived(): boolean

You can check the result of the HaltSignalReceived() function anywhere in your script. If it returns true it means that an administrator (or the Operating System itself) has requested the execution of the current script to be stopped.

Once a halt request is received, the execution of the script will be stopped regardless of whether or not you check this value, but checking it gives you the chance to handle the situation gracefully.


  ConsoleFeedback = true;
  var scli = new SftpClient();
  scli.Host = '';
  scli.User = 'some_username';
  scli.PassFromSecret = 'name_of_the_secret_password';
  if (scli.Connect()) {
    watchr = NewFsWatcher();
    watchr.WatchDir('C:\\Docs', true);
    while (true) {
      if (HaltSignalReceived()) {
        break; // break infinite loop if halt signal was received
      evt = watchr.Events() // gets the list of pending events to be handled
      if (evt.length > 0) {
        for (var i = 0; i < evt.length; i++) {
          if (evt[i].Event == 'WRITE') {
            scli.UploadWithPath(evt[i].Object, '/realtimebackup', 0);
  scli = null;