Jump to content

Progress function hangs the installation


poppe
 Share

Recommended Posts

Hello

I'm writing a code that automates the installation of a specifc software.

During the installation process i need a separate window to show the progress with a timer.

My test code:

_Timer()

ControlSend("My Application", "", "[CLASS:NewButton; INSTANCE:1]", "{ENTER}")
Exit

Func _Timer()
   ProgressOn("Progress Meter", "Increments every second", "0 percent")
For $i = 10 To 100 Step 10
    Sleep(1000)
    ProgressSet($i, $i & " percent")
Next
ProgressSet(100, "Done", "Complete")
Sleep(500)
ProgressOff()
EndFunc   ;==>_Main

The Timer will start running, but the ControlSend will not happen until the timer has ran out.

I need the timer to start on the background, and the main code to progress normally at the same time, so it can install the software.

How can i run the timer as a separate process?

Link to comment
Share on other sites

Hi and thanks for the reply

Even if i don't use sleep, the program hangs in the IF loop. It will wait until the IF has stopped executing, and proceed only after that.

How can i run the progressbar function as a different process, so it does not interrupt the installation process?

I would like the attached code to run during the installation process. If I know the installation takes for example 500 seconds, so i could pre-set it to 500.

#include <Guiconstants.au3>
    Local $progressbar
    Local $i = 0
    Sleep(500)
    GUICreate("babab", 180, 50)
    $progressbar = GUICtrlCreateProgress(10, 15, 160, 20)
    $label = Guictrlcreatelabel("",10,18,160,20,0x01)
    Guictrlsetbkcolor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUISetState()
    While Guigetmsg() <> -3
        $i = $i + 1
        GUICtrlSetData($progressbar, $i)
        GUICtrlSetData($label,$i)
        Sleep(20)
        If $i = 100 Then $i = 0
    WEnd
    GUIDelete()
Edited by poppe
Link to comment
Share on other sites

Take a look at this.

#include <Math.au3>

Global $iTimer = TimerInit()
Global $iUpdateDelay = 1000 ; 1 sec

Global $hWnd = GUICreate("Test")
Global $hProgress = GUICtrlCreateProgress(10, 10, 200, 20)

GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch

    If (TimerDiff($iTimer) >= $iUpdateDelay) Then
        $iTimer = TimerInit()

        $iPercentage = GUICtrlRead($hProgress)
        If ($iPercentage < 100) Then
            GUICtrlSetData($hProgress, _Min($iPercentage + 10, 100))
        EndIf
    EndIf
WEnd

; the _Min isn't really necessary in this sample.
; it's just a safety check if you are using other values for updating the progessbar
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

OK thanks.

I understand how your code works, but i don't understand how i can run it as a separate process.

I have the following style code, that installs my application. Sleep is used to wait until the setup handles files, and then shows the next window on screen. This way the enter is sent to proper window.

If Not ShellExecute("setup.exe") Then
            MsgBox(48, "My application", "Could not launch setup.")
            Exit
EndIf
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:1]", "{ENTER}")
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}")
Sleep (10000)
WinActivate("My application - locales","")
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}")

Where should i input your code, so the progressbar shows at the same time the installation proceeds :) ?

Link to comment
Share on other sites

Let me get this straight.

You want one application to automate an installation and one application that shows a progress bar?

Why don't you combine those two in one script?

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

You don't need a whole new script / process for creating another Window in which you can show a progress bar.

You can simply create another GUI window and show the progress there.

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Hello

In the following code i create the GUI for the progress bar:

#include <Math.au3>
Global $iTimer = TimerInit()
Global $iUpdateDelay = 1000 ; 1 sec
Global $hWnd = GUICreate("Test")
Global $hProgress = GUICtrlCreateProgress(-1, -1, 500, 20)
GUISetState(@SW_SHOW, $hWnd)
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
    If (TimerDiff($iTimer) >= $iUpdateDelay) Then
        $iTimer = TimerInit()
        $iPercentage = GUICtrlRead($hProgress)
        If ($iPercentage < 100) Then
            GUICtrlSetData($hProgress, $iPercentage + 1)
        EndIf
    EndIf
WEnd

The code itself is not finished yet, but shows the general idea.

My application installation code:

If Not ShellExecute("setup.exe") Then
            MsgBox(48, "My application", "Could not launch setup.")
            Exit
EndIf
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:1]", "{ENTER}")
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}")
Sleep (10000)
WinActivate("My application - locales","")
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}")

When the progress bar GUI window is created, it will hang in the While loop, and never progress further. If i just paste the second code after it, it will never get executed.

Installing my application takes 50 seconds, so i can preset the progress bar to 50 seconds also and it will match.

How to combine the two codes?

Link to comment
Share on other sites

You could do something like this:

Global $hWnd = GUICreate("", 300, 40)
Global $hProgress = GUICtrlCreateProgress(10, 10, 280, 20)

GUISetState()

If (Not ShellExecute("setup.exe")) Then
    Exit MsgBox(48, "My application", "Could not launch setup.")
EndIf

GUICtrlSetData($hProgress, 20)
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:1]", "{ENTER}")
GUICtrlSetData($hProgress, 40)
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}")
GUICtrlSetData($hProgress, 60)
Sleep (10000)
WinActivate("My application - locales","")
GUICtrlSetData($hProgress, 80)
Sleep (10000)
ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}")
GUICtrlSetData($hProgress, 100)
Sleep (10000)

While 1
    Switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch
WEnd
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...