rot3r Posted January 9 Posted January 9 hello Im creating an app that download several file.i have problem that when start first download and using a loop to monitor ans update status on a list view , somehow script is frozen and not working. is ther any way to send loops in background and better way to update listview? ; Wait for the download to complete : Do $currentDown[0][3]=InetGetInfo($hDownload, $INET_DOWNLOADREAD) Sleep(250) _GUICtrlListView_DeleteAllItems($idListview) _GUICtrlListView_AddArray($idListview,$currentDown ) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
Developers Jos Posted January 9 Developers Posted January 9 Assume this is not the total script and yes the script will "hang in this loop" until this single download is done. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Developers Jos Posted January 9 Developers Posted January 9 Sure, but you will have to share a script that demonstrates the issue so we can see what you are exactly doing and how to implement this. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Nine Posted January 9 Posted January 9 I answer something very similar recently : “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Developers Jos Posted January 9 Developers Posted January 9 No multi-threading is required in this case as the download is performed already in the background, so all that is required is to store the handles of each submitted download in an array, and then loop through this array getting the status for each active download and handle the ended sessions. ioa747 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
rot3r Posted January 9 Author Posted January 9 1 hour ago, Jos said: No multi-threading is required in this case as the download is performed already in the background, so all that is required is to store the handles of each submitted download in an array, and then loop through this array getting the status for each active download and handle the ended sessions. i already sent the download to background,but the way you mentioned is fine if we just have download progress , but because the download may take time i want to other aspect of gui can work for example user can add more download to list. Global $hDownload = InetGet($url , @ScriptDir&"\"&$sFileName&$sExtension, BitOR( $INET_IGNORESSL, $INET_BINARYTRANSFER), $INET_DOWNLOADBACKGROUND)
Developers Jos Posted January 9 Developers Posted January 9 9 minutes ago, rot3r said: but because the download may take time i want to other aspect of gui can work for example user can add more download to list. Understand, hence my question for a more complete script so we can assist. rot3r 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
rot3r Posted January 11 Author Posted January 11 On 1/9/2025 at 6:22 PM, Jos said: Understand, hence my question for a more complete script so we can assist. it's function that call from main gui : Func downAdd() Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" for $vElement In $idDown[0][2] local $currentDown[10][5] Local $aPathSplit = _PathSplit(json_get($vElement,".download_link"), $sDrive, $sDir, $sFileName, $sExtension) $url =json_get($vElement,".download_link") ;"File Name|Size|Status|Transfer rate|Date Added" $currentDown[0][0]=$idDown[0][0] $currentDown[0][1]=$idDown[0][1] $currentDown[0][2]=floor((InetGetSize($url)/1024)/1024) Global $hDownload = InetGet($url , @ScriptDir&"\"&$sFileName&$sExtension, BitOR( $INET_IGNORESSL, $INET_BINARYTRANSFER), $INET_DOWNLOADBACKGROUND) ; Wait for the download to complete : Do $currentDown[0][3]=InetGetInfo($hDownload, $INET_DOWNLOADREAD) Sleep(250) _GUICtrlListView_DeleteAllItems($idListview) _GUICtrlListView_AddArray($idListview,$currentDown ) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) ; total bytes received and filesize : ConsoleWrite("BytesSize InetGetInfo = " & InetGetInfo($hDownload, $INET_DOWNLOADREAD) & @CRLF) ConsoleWrite("BytesSize Local File = " & FileGetSize($url) & @CRLF) InetClose($hDownload) next EndFunc and this is part of code that create listview : $hGUIDown = GUICreate("Download",980,620, 115, 90,$WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xffffff,$hGUIDown) Local $idListview = GUICtrlCreateListView("File Name|Size|Status|Transfer rate|Date Added", 25, 40, 900, 550,-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES) ) ;,$LVS_SORTDESCENDING) _GUICtrlListView_SetColumnWidth($idListview,0,0 ) _GUICtrlListView_SetColumnWidth($idListview,1,200 ) _GUICtrlListView_SetColumnWidth($idListview,2,70 ) Local $btnDown = GUICtrlCreateButton("", 30, 0, 80, 35,$BS_BITMAP) _GUICtrlButton_SetImageList($btnDown,$imageListBtn[4],4,0) Local $btnPause = GUICtrlCreateButton("", 120, 0, 40, 35,$BS_BITMAP) _GUICtrlButton_SetImageList($btnPause,$imageListBtn[5],4,0) Local $btnOpen = GUICtrlCreateButton("", 170, 0, 40, 35,$BS_BITMAP) _GUICtrlButton_SetImageList($btnOpen,$imageListBtn[6],4,0) Local $btnTrash = GUICtrlCreateButton("", 220, 0, 40, 35,$BS_BITMAP) _GUICtrlButton_SetImageList($btnTrash,$imageListBtn[7],4,0) GUISetState(@SW_hide) and there is a main gui like tab that user can change between the download page and select files to download
argumentum Posted January 11 Posted January 11 4 hours ago, rot3r said: and this is part of code that create listview ...I've been watching this thread for days waiting to steal your code but you only post bits and pieces. Quite frustrating. Since you don't want to post running code ( one that I could copy'n'paste to run on my side ) the advice is: don't "Until InetGetInfo()", instead watch the InetGetInfo() in the main loop and once they are all done, they are done. It all runs in the background anyway. Why wait in a "Until InetGetInfo()" ?, might as well run it in the foreground if you're gonna "Until InetGetInfo()". Cheers Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
rot3r Posted Thursday at 10:29 AM Author Posted Thursday at 10:29 AM its complete code with all dependencies,in main page first select the first item after that in download page click on download. with your help i move the InetGetInfo in the main loop. the problem is that i want to update the download status in the listview and i think its not a good method to "_GUICtrlListView_DeleteAllItems" and "_GUICtrlListView_AddArray" in every cycle.also if put sleep in main loop the program become unresponsive. JBdl.zip
argumentum Posted Thursday at 01:05 PM Posted Thursday at 01:05 PM 2 hours ago, rot3r said: complete code with all dependencies NotifyBox.au3 and GUIScrollbars_Ex.au3 are not there and I don't know where to get it from. also, stuff like ""بارگذاری نرم افزارها","درحال اتصال به سرور, لطفا چند لحظه منتظر بمانید"" ( "Loading software", "Connecting to the server, please wait a few moments" ) would be good to have it internationalized or, since this forum is English only, share it in English. Am Hispanic but share everything in English because it makes sense to use a common language since becoming a polyglot is harder than becoming a coder, for me anyway. 2 hours ago, rot3r said: also if put sleep in main loop the program become unresponsive. Then don't. Does not need the "Sleep(250)". That is there for the example only given that there is nothing from regulating a wait time like GUIGetMsg() to handle that. Nice looking code. Easy to read Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Nine Posted Thursday at 03:29 PM Posted Thursday at 03:29 PM (edited) Well giving your full script with missing parts is not helping us very much. But since I am waiting for my car to get maintenance, here my take on what I think you want : expandcollapse popup#include <File.au3> #include <GUIConstants.au3> #include <InetConstants.au3> #include <GuiListView.au3> Opt("MustDeclareVars", True) Example() Func Example() Local $aDownList[20][6] Local $hGUI = GUICreate('Example', 600, 600, 200, 200, $WS_SIZEBOX) Local $idListView = GUICtrlCreateListView("ID|Status|File", 50, 20, 500, 400) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) _GUICtrlListView_SetColumnWidth($idListView, 2, 300) Local $idDownload = GUICtrlCreateButton("Add DownLoad", 50, 500, 150, 25) GUISetState() Local $iIndex While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idDownload ;$iIndex = AddDown($aDownList, "http://www.autoitscript.com/autoit3/files/beta/update.dat", _TempFile(@ScriptDir, Default, ".txt", 10)) $iIndex = AddDown($aDownList, "https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3.zip", _TempFile(@ScriptDir, Default, ".zip", 10)) $aDownList[$iIndex][5] = GUICtrlCreateListViewItem($aDownList[$iIndex][0] & "|0.0%|" & $aDownList[$iIndex][3], $idListView) EndSwitch VerifyDownLoad($idListView, $aDownList) WEnd EndFunc ;==>Example Func AddDown(ByRef $aList, $sURL, $sFile) For $i = 0 To UBound($aList) - 1 If Not $aList[$i][0] Then ExitLoop Next If $i = UBound($aList) Then Return SetError(1) $aList[$i][0] = InetGet($sURL, $sFile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) $aList[$i][1] = 0 $aList[$i][2] = 0 $aList[$i][3] = $sFile $aList[$i][4] = $sURL Return $i EndFunc ;==>AddDown Func VerifyDownLoad($idLV, ByRef $aList) Local $sStatus, $iValue Local $tInfo = DllStructCreate($tagLVFINDINFO) $tInfo.Flags = $LVFI_PARAM For $i = 0 To UBound($aList) - 1 If Not $aList[$i][0] Then ContinueLoop If InetGetInfo($aList[$i][0], $INET_DOWNLOADCOMPLETE) Then $sStatus = "Complete" InetClose($aList[$i][0]) $aList[$i][0] = 0 Else $iValue = InetGetInfo($aList[$i][0], $INET_DOWNLOADREAD) If $iValue = $aList[$i][2] Then ContinueLoop If Not $aList[$i][1] Then $aList[$i][1] = InetGetInfo($aList[$i][0], $INET_DOWNLOADSIZE) $sStatus = StringFormat("%.1f%%", $iValue / $aList[$i][1] * 100) $aList[$i][2] = $iValue EndIf $tInfo.Param = $aList[$i][5] $iValue = _GUICtrlListView_FindItem($idLV, -1, $tInfo) _GUICtrlListView_SetItem($idLV, $sStatus, $iValue, 1) Next EndFunc ;==>VerifyDownLoad ps. see how you can make a runable script without having the full blown code... Edited Friday at 05:30 PM by Nine missing inetclose argumentum and rot3r 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
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