Jump to content

Simple progress bar (in another thread)


SpookMeister
 Share

Recommended Posts

It is fairly self explanatory, but basically I'm just making the script write and execute a second script that is just a progress bar, then providing a method of killing that second script when you are done.

I guess you could also call it a "bailing wire and duct tape" form of multi-threading :D

; When you want to notify the user that your main script will be busy for a while
_StartProgress("Sending Email...") ; Put whatever comment you want

; Here I am just simulating your main program still running while the progress bar does its thing
$timer = TimerInit()
$seconds = 25
While TimerDiff($timer) / 1000 < $seconds
    Sleep(100)
    ToolTip("Main program running for " & Int(TimerDiff($timer) / 1000) & " seconds")
WEnd

; When you want to get rid of the progress bar
_StopProgress()

; ------------------------------------------------------------
; stick the following code at the end of your script somewhere
; ------------------------------------------------------------

Func _StartProgress($s_comment = "Please Stand By")
    $s_path = @ScriptDir & "\progress.au3"
    $h_file = FileOpen($s_path, 2)
    $s_code = 'AutoItSetOption ("TrayIconHide",1)' & @CRLF & _
            'AutoItWinSetTitle("MyProgressBar")' & @CRLF & _
            'Dim $percent = 0' & @CRLF & _
            'ProgressOn("In Progress...", "' & $s_comment & '")' & @CRLF & _
            'While ProcessExists(' & @AutoItPID & ')' & @CRLF & _
            'ProgressSet($percent)' & @CRLF & _
            '$percent += 5' & @CRLF & _
            'If $percent > 100 Then $percent = 0' & @CRLF & _
            'Sleep(500)' & @CRLF & _
            'WEnd' & @CRLF
    FileWrite($h_file, $s_code)
    FileClose($h_file)
    Run(@AutoItExe & " /AutoIt3ExecuteScript progress.au3", @ScriptDir)
EndFunc   ;==>_StartProgress

Func _StopProgress()
    If WinExists("MyProgressBar") Then WinKill("MyProgressBar")
    FileDelete(@ScriptDir & "\progress.au3")
EndFunc   ;==>_StopProgress

The progress bar just continues to go from 0% to 100% until you tell it to stop.

Click on the attachment to see what the progress bar looks like

post-7657-1238168517_thumb.jpg

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Edited initial code to make sure the progress bar quits if the main program dies before it can call the _StopProgress() function

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • 2 weeks later...
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...