Welcome !
         

 Avoid HTA interface freeze during long process

Author Message
axplains

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 5/5/2010
  • Status: offline
Avoid HTA interface freeze during long process Wednesday, May 05, 2010 9:29 PM (permalink)
0
Hello everyone,

I have a function which retrieves existing domains in the network and stores the names in a disconnected recordset (to show them in a part of the page).

It is called inside a HTA, and while it runs (it is a somewhat lengthy process, around 30 seconds) the HTA interface is completely frozen.
I tried to show an animated GIF to indicate a running task, but it gets frozen too.
I tried various techniques like "Sleep", "SetInterval", "SetTimeOut", but nothing seems to work acceptably.
Ideal would be to make it run as a separate thread/process, but I did not find any useful information.
Does anyone have some suggestions about that?
Thank you very much.

Function GetDomainsAndWorkgroups
     ' DISCONNECTED RECORDSET
     Const adVarChar = 200
     Const MaxCharacters = 255
     Set DataList = CreateObject("ADOR.Recordset")
     DataList.Fields.Append "Domain", adVarChar, MaxCharacters
     DataList.Open
     Set NameSpace = GetObject("WinNT:")
     For Each DomainObj In NameSpace
         DataList.AddNew
         DataList("Domain") = DomainObj.Name
         DataList.Update
         Set DomainObj = Nothing
     Next
     Set NameSpace = Nothing
     DataList.Sort = "Domain" ' & " ASC"
     Set GetDomainsAndWorkgroups = DataList
     Set DataList = Nothing
 End Function


 
#1
    ginolard

    • Total Posts : 1347
    • Scores: 21
    • Reward points : 0
    • Joined: 8/11/2005
    • Status: offline
    Re:Avoid HTA interface freeze during long process Wednesday, May 05, 2010 11:01 PM (permalink)
    0
    There's no threading in vbscript (well, not really...it's complicated.) 

    Are you just wanting to list all Domains in an Active Directory forest?  If so, there's a much better way.  The WinNT provider WILL be slower.
    <message edited by ginolard on Wednesday, May 05, 2010 11:20 PM>
    Author of ManagePC - http://managepc.net

     
    #2
      axplains

      • Total Posts : 5
      • Scores: 0
      • Reward points : 0
      • Joined: 5/5/2010
      • Status: offline
      Re:Avoid HTA interface freeze during long process Wednesday, May 05, 2010 11:54 PM (permalink)
      0
      Thank you for your reply.

      I am trying to list all domains in all available forests.
      Can you please point me to the "better way"?
      And, just out of curiosity, to some sources about "complicated" threading in vbscript?

      Thanks a lot!

       
      #3
        milnet

        • Total Posts : 23
        • Scores: 0
        • Reward points : 0
        • Joined: 4/23/2010
        • Status: offline
        Re:Avoid HTA interface freeze during long process Monday, May 10, 2010 2:00 AM (permalink)
        0
        There is a way to update the OSD but it will slow down the script.  Simply use:

        With CreateObject("WScript.Shell")
          .run "%comspec% /c exit", 0, True
        End With

        To combat it slowing down too much I simply put it in a calculation:

        a = 0
        If ( a Mod 20 ) = 0 Then
          With CreateObject("WScript.Shell")
            .run "%comspec% /c exit", 0, True
          End With
        End If
        a = a + 1
         
        #4
          rasimmer

          • Total Posts : 2386
          • Scores: 163
          • Reward points : 0
          • Joined: 3/19/2009
          • Location: Richmond, VA
          • Status: offline
          Re:Avoid HTA interface freeze during long process Tuesday, May 11, 2010 1:43 AM (permalink)
          0
          The problem is that HTA's use MSHTA.exe to process anything the HTA does.  The best thing that you can do is hide the HTA (you should be able to search for solutions for this, it's basically moving the HTA to -1600 so it's not on the screen, use InternetExplorer.Application to create a popup with your message and then start the process.  Once the process completes, you can close your popup, move the HTA back on the screen and you're good to go.  As you've seen, if the MSHTA is processing something then that's all it's doing, so it's going to ignore sleeps or anything else until it's done running the loop you have it in, which goes back to ginolard's comments about threading.
           
          #5
            axplains

            • Total Posts : 5
            • Scores: 0
            • Reward points : 0
            • Joined: 5/5/2010
            • Status: offline
            Re:Avoid HTA interface freeze during long process Tuesday, May 11, 2010 2:01 AM (permalink)
            0
            I will try both, thank you all.
             
            #6
              Drunlar

              • Total Posts : 1
              • Scores: 0
              • Reward points : 0
              • Joined: 2/6/2012
              • Status: offline
              Re:Avoid HTA interface freeze during long process Monday, February 06, 2012 11:30 AM (permalink)
              0
              I needed to wait for a DLL call to return yet at the same time accept more input from the HTA. After a lot of research I came up with a process that would allow you to fork the code running 2 lines of code  in parallel. NOTE Echo is a sub not included that reports results to a HTML TEXTAREA


              Dim iThreadID : iThreadID = window.setInterval("Thread", 300)

              Do
              Echo ("I am waiting for a global to be set in 'Sub Thread' letting me know I can break or how to handle results")
              Sleep 1
              Loop

              Echo ("Fire and sleep completed")


              '================================================================================================
              Sub Thread
              Echo "Fire and wait for return here"
              End Sub

              '================================================================================================
              Sub Sleep(intSeconds)
              Dim objShell, strCommand
              Set objShell = CreateObject("Wscript.Shell")
              strCommand = "%COMSPEC% /c ping -n " & 1 + intSeconds & " 127.0.0.1>nul"
              objShell.Run strCommand, 0, True
              Set objShell = Nothing
              End Sub
               
              #7
                t0m

                • Total Posts : 1
                • Scores: 0
                • Reward points : 0
                • Joined: 6/17/2011
                • Status: offline
                Re:Avoid HTA interface freeze during long process Wednesday, February 22, 2012 4:38 AM (permalink)
                0
                Drunlar, this looks really good but I don't quite understand how to use it!
                 
                I would like my HTA to launch a program and continue updating an animated GIF. Where would the line to launch the program go in your example code? How would I then test to see if it has finished before moving on?
                 
                #8
                  Online Bookmarks Sharing: Share/Bookmark

                  Jump to:

                  Current active users

                  There are 0 members and 1 guests.

                  Icon Legend and Permission

                  • New Messages
                  • No New Messages
                  • Hot Topic w/ New Messages
                  • Hot Topic w/o New Messages
                  • Locked w/ New Messages
                  • Locked w/o New Messages
                  • Read Message
                  • Post New Thread
                  • Reply to message
                  • Post New Poll
                  • Submit Vote
                  • Post reward post
                  • Delete my own posts
                  • Delete my own threads
                  • Rate post

                  2000-2014 ASPPlayground.NET Forum Version 3.9