Mindbend Posted January 10, 2019 Posted January 10, 2019 I have written a function to automatically download several files from the internet. I want to do something with the function which I am currently unable to do: 1. I want to be able to stop the function midway as the function takes several minutes to execute and sometimes I would like to stop it and start another function. My GUI has a button attached to the function which starts it, I am looking to have another button which stops(not exit, I have read that pause may be the go). The problem is that AutoIT can only execute one function at a time, so I am trying to wrap my head around this. I am not looking for a hotkey, rather I am looking for a function which I can attach to a button to stop it. Func dlbooks() Local $hDownload = InetGet("https:mydoc", "C:\myplace", $INET_FORCERELOAD) Local $hDownload = InetGet("https:mydoc", "C:\myplace", $INET_FORCERELOAD) Local $hDownload = InetGet("https:mydoc", "C:\myplace", $INET_FORCERELOAD) Local $hDownload = InetGet("https:mydoc", "C:\myplace", $INET_FORCERELOAD) Local $hDownload = InetGet("https:mydoc", "C:\myplace", $INET_FORCERELOAD) EndFunc
FrancescoDiMuro Posted January 10, 2019 Posted January 10, 2019 51 minutes ago, Mindbend said: My GUI has a button attached to the function which starts it Post the entire code so By the way, do what mikell just suggested. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Mindbend Posted January 11, 2019 Author Posted January 11, 2019 20 hours ago, mikell said: Please have a look at the Wiki Hi mikell, Thanks for the prompt response. I had come across this page while I was searching for an answer but was hoping for a simpler way to do it. I assume I would have to use the "Windows message handler" method. I will give that a go 20 hours ago, FrancescoDiMuro said: Post the entire code so By the way, do what mikell just suggested. Yup will do. Here is the entire code. I have changed the file download path for privacy reasons. expandcollapse popup; Script Start - #include <InetConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <FileConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIResizeMode", $GUI_DOCKHCENTER) Opt("GUIResizeMode", $GUI_DOCKHCENTER) #Region ### START Koda GUI section ### Form=c:\me\form1.kxf $DownloadGB = GUICtrlCreateButton("DLer", 40, 64, 137, 41) $backup = GUICtrlCreateButton("Backuper", 42, 136, 137, 41) $Exite = GUICtrlCreateButton("Exit", 404, 200, 137, 41) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $DownloadGB dlbooks() Case $backup bubooks() Case $Exite _Exit() EndSwitch WEnd Func bubooks() $Source = "C:\me" $Dest = "C:\me\" & @YEAR & "-" & @MON & "-" & @MDAY & "(@" & @HOUR & "" & @MIN & "" & @SEC & ")" DirCreate($Dest) Sleep(3000) FileMove($Source & "\*.*", $Dest,1) EndFunc Func _Exit() Exit 0 EndFunc Example() Func dlbooks() ; Display a progress bar window. ; ProgressOn("Download", "Downloading grade books now, please wait", "0%", -1, -1, BitOR($DLG_NOTONTOP, $DLG_MOVEABLE)) ; Update the progress value of the progress bar window every second. ; For $i = 1 To 100 Step 1 ; Sleep(1000) ; ProgressSet($i, $i & "%") ; Next ; Set the "subtext" and "maintext" of the progress bar window. ;ProgressSet(100, "Done", "Complete") ; Sleep(5000) ; Close the progress window. ;ProgressOff() ; Download the file in the background with the selected option of 'force a reload from the remote site.' ; I have changed the file download path for privacy reasons Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) Local $hDownload = InetGet("https:google.com", "C:\me.txt", $INET_FORCERELOAD) EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now