CYBRIX Posted November 15, 2021 Share Posted November 15, 2021 So, I have a GUI running in GUIOnEventMode, and Every now and then, when my script enters a blocking function for an extended period of time, the entire window will freeze. I use _WinAPI_SetTimer to update the UI elements of the AutoIt window with global variables that get updated throughout the script (including in said blocking function), but while the script is looping (Do ... Until) in said function, the GUI will cease to update, even though the variables are being updated and the Update calls (_WinAPI_SetTimer) are being executed. (Otherwise everything works fine.) Can anyone tell me how to stop this behavior, or tell me what may be causing it (or maybe how AutoIt manages its GUI elements)? Link to comment Share on other sites More sharing options...
Zedna Posted November 15, 2021 Share Posted November 15, 2021 (edited) In your Do/Until loop add calling/intercepting of GuiGetMsg(). Note: This apply in Message mode (not Event mode) ... Edited November 15, 2021 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
CYBRIX Posted November 16, 2021 Author Share Posted November 16, 2021 So I made a script to show what I am talking about, but it doesn't freeze... Maybe it's because the blocking function in my original code does file transfers... The file transfer in my original code is performed using FileOpen() in binary mode, then reading blocks of data and writing it into a different new file. Could it be that the FileRead() and FileWrite() process manages to freeze up everything else somehow (slow read\write or something)? The thing is that everything freezes, like, not even the _WinAPI-timer manages to update the window (I know because there is a "Runtime" counter, just like in my example script, and even that freezes). Here's the example script that is set up similarly to my original program, but unfortunately does not behave the same: (the program that started this thread is a LOT longer) expandcollapse popup; Example script #include <WinAPISys.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ;GUIOnEventMode = Yes Opt("MustDeclareVars", 1) Local Const $nWidth = 200, $nHeight = 200 Local Const $nRefreshRate = 25, $nRefreshRateMs = 1000 / $nRefreshRate Global $sLabelData = "Not yet updated", $nLoops Global $STATE = 0, $nTime Global Const $ST_END = -1 Global Const $nArraySize = 500, $nBiggestNumberToProcess = 1000 Global $aRandomNumbers[$nArraySize] For $i = 0 To $nArraySize - 1 $aRandomNumbers[$i] = Round(Random(1, $nBiggestNumberToProcess), 5) Next Global Const $hWnd = GUICreate("Freeze Example", $nWidth, $nHeight) Global Const $hLabel = GUICtrlCreateLabel($sLabelData, 10, 10, $nWidth - 20, $nHeight - 60) Global Const $hSpeedLabel = GUICtrlCreateLabel("", 10, $nHeight - 60, $nWidth - 20, 50) Global Const $hElapsedTime = TimerInit() GUISetOnEvent($GUI_EVENT_CLOSE, _Close) GUISetState(@SW_SHOW, $hWnd) Global Const $pUpdateFunction = DllCallbackRegister("_UpdateUI", "none", "") Global Const $hRefreshTimer = _WinAPI_SetTimer($hWnd, 0, $nRefreshRateMs, DllCallbackGetPtr($pUpdateFunction)) ;Let windows update UI elements OnAutoItExitRegister(_EndScript) ;Main Loop While $STATE <> $ST_END _BlockingFunction() ;Will get stuck in function for up to 10 seconds at a time WEnd Exit Func _BlockingFunction() ;Just keeping the system busy $nTime = Random(10, 10000, 1) local $hProcessTimer = TimerInit() Local $index1, $index2, $index3 Local $sTempLabelText Do $index1 = Random(0, $nArraySize - 1, 1) $index2 = Random(0, $nArraySize - 1, 1) $index3 = Random(0, $nArraySize - 1, 1) if $aRandomNumbers[$index2] <= 0 Then $aRandomNumbers[$index2] = 1 if $aRandomNumbers[$index3] <= 0 Then $aRandomNumbers[$index3] = 1 $sTempLabelText = "Did mafs:" & @CRLF & @CRLF if $aRandomNumbers[$index2] + $aRandomNumbers[$index3] < $nBiggestNumberToProcess Then $aRandomNumbers[$index1] = Round($aRandomNumbers[$index2] + $aRandomNumbers[$index3], 5) $sTempLabelText &= $aRandomNumbers[$index2] & @CRLF & "+" & @CRLF & $aRandomNumbers[$index3] Elseif $aRandomNumbers[$index2] > $aRandomNumbers[$index3] Then $aRandomNumbers[$index1] = Round($aRandomNumbers[$index2] - $aRandomNumbers[$index3], 5) $sTempLabelText &= $aRandomNumbers[$index2] & @CRLF & "-" & @CRLF & $aRandomNumbers[$index3] Else $aRandomNumbers[$index1] = Round($aRandomNumbers[$index3] - $aRandomNumbers[$index2], 5) $sTempLabelText &= $aRandomNumbers[$index3] & @CRLF & "-" & @CRLF & $aRandomNumbers[$index2] EndIf $sTempLabelText &= @CRLF & "=" & @CRLF & $aRandomNumbers[$index1] $sLabelData = $sTempLabelText $nLoops += 1 Until $STATE = $ST_END Or TimerDiff($hProcessTimer) > $nTime EndFunc Func _Close() $STATE = $ST_END EndFunc Func _EndScript() _WinAPI_KillTimer($hWnd, $hRefreshTimer) DllCallbackFree($pUpdateFunction) GUIDelete($hWnd) EndFunc Func _UpdateUI() Local $speed = $nLoops / $nRefreshRateMs * 1000 $nLoops = 0 GUICtrlSetData($hLabel, $sLabelData) GUICtrlSetData($hSpeedLabel, "Hz = " & $speed & @CRLF & "Blocking function loop time: " & round($nTime / 1000, 1) & "s" & @CRLF & @CRLF & "Runtime: " & _FormatTime(TimerDiff($hElapsedTime))) EndFunc Func _FormatTime($nTime) Local $sReturn = "", $Temp if $nTime > 60000 Then $Temp = Round($nTime / 60000) $sReturn &= $Temp & "m " $nTime -= $Temp * 60000 EndIf $sReturn &= Round($nTime / 1000) & "s" Return $sReturn EndFunc Link to comment Share on other sites More sharing options...
mLipok Posted November 16, 2021 Share Posted November 16, 2021 Add Sleep(10) to yours Do Until Loop Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Nine Posted November 16, 2021 Share Posted November 16, 2021 (edited) Hmm. Like you said your example script does not show the same behavior as you described in your OP. Even if I increase the random timer from 10000 to 100000. I trust that there is another issue in your original script. To find it you should put some tracing messages in your script to see where it goes and when... Edited November 16, 2021 by Nine “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 Link to comment Share on other sites More sharing options...
CYBRIX Posted November 16, 2021 Author Share Posted November 16, 2021 (edited) There we go. Now this Example script freezes in the same way.| (You need to use larger files [750 MB +] to really see it suffer) I don't know how AutoIt works, so I'm really curious what it wants from me, so that it can manage its UI throughout my script. I hope this will help troubleshooting. Here's the script: expandcollapse popup; Example script #include <WinAPISys.au3> #include <GUIConstants.au3> #include <File.au3> Opt("GUIOnEventMode", 1) ;GUIOnEventMode = Yes Opt("MustDeclareVars", 1) ;Window properties Local Const $nWidth = 200, $nHeight = 200 Local Const $nRefreshRate = 25, $nRefreshRateMs = 1000 / $nRefreshRate Global $STATE = 0 Global Const $ST_END = -1 Global $sSelectedFolder ;Prompt for folder Do $sSelectedFolder = FileSelectFolder("Select a folder with a few files in it", @UserProfileDir & "\Documents") if @error Then Exit MsgBox(0, "Bye now", "Ended program.") Until FileExists($sSelectedFolder) ;Ensure I am not liable If MsgBox(49 + 256, "Warning", "This script clones the folder you selected (in the same directory)." & @CRLF & "It copys and deletes files until you stop it." & @CRLF & @CRLF & "I advise you not to proceed if you selected a folder on an SSD." & @CRLF & "I'M NOT RESPONSABLE FOR REDUCED SSD LIFE TIMES!") <> 1 Then Exit ;List files in folder Global $aFiles = _FileListToArrayRec($sSelectedFolder, "*", 13) if Not IsArray($aFiles) Or $aFiles[0] = 0 Then Exit MsgBox(16, "Bad pick", "It would seem the folder is empty." & @CRLF & "Ended Program.") ;Some variables Global Const $hElapsedTime = TimerInit(), $nBlockSize = 8000 Global $nTransfered = 0, $hProcessTimer Global $sLabelData = "Not yet updated", $nLoops Global $aDirCreated[2] = [False, ""] ;GUI Elements Global Const $hWnd = GUICreate("Freeze Example", $nWidth, $nHeight) Global Const $hLabel = GUICtrlCreateLabel($sLabelData, 10, 10, $nWidth - 20, $nHeight - 60) Global Const $hSpeedLabel = GUICtrlCreateLabel("", 10, $nHeight - 60, $nWidth - 20, 50) GUISetOnEvent($GUI_EVENT_CLOSE, _Close) GUISetState(@SW_SHOW, $hWnd) ;Let windows update UI elements Global Const $pUpdateFunction = DllCallbackRegister("_UpdateUI", "none", "") Global Const $hRefreshTimer = _WinAPI_SetTimer($hWnd, 0, $nRefreshRateMs, DllCallbackGetPtr($pUpdateFunction)) OnAutoItExitRegister(_EndScript) ;Ensure everything is closed properly ;Main Loop While $STATE <> $ST_END For $i = 1 To $aFiles[0] $hProcessTimer = TimerInit() _BlockingFunction($aFiles[$i], $sSelectedFolder, $sSelectedFolder & " (Copy)") ;The blocking function Next WEnd Exit Func _BlockingFunction($sFileName, $sSource, $sDestination) ;Clone the selected folder local $sData, $nError if Not $aDirCreated[0] And FileExists($sDestination) Then Do $sDestination &= " (Copy)" Until Not FileExists($sDestination) EndIf DirCreate($sDestination) $aDirCreated[0] = True $aDirCreated[1] = $sDestination $sDestination &= "\" & $sFileName if FileExists($sDestination) Then FileDelete($sDestination) _FileCreate($sDestination) Local $hCurrentSource = FileOpen($sSource & "\" & $sFileName, 16) Local $hCurrentDest = FileOpen($sDestination, 1) $sLabelData = "Copying: ...\" & $sFileName Do $sData = FileRead($hCurrentSource, $nBlockSize) $nError = @error FileWrite($hCurrentDest, $sData) $nLoops += 1 if $nError = -1 Then $nTransfered += StringLen($sData) ExitLoop Else $nTransfered += $nBlockSize EndIf Until $STATE = $ST_END FileClose($hCurrentSource) FileClose($hCurrentDest) EndFunc Func _Close() $STATE = $ST_END EndFunc Func _EndScript() if $aDirCreated[0] And MsgBox(36, "Delete created folder?", "Do you want to delete " & $aDirCreated[1] & "?" & @CRLF & "(No, that is not the original. But do double check.)") = 6 Then $sLabelData = "Removing: " & $aDirCreated[1] if DirRemove($aDirCreated[1], 1) = 0 Then MsgBox(16, "Error", "Failed to remove: " & $aDirCreated[1] & @CRLF & "Guess you'll have to do that. sry...") Else MsgBox(0, "Success", "Folder was removed.") EndIf EndIf _WinAPI_KillTimer($hWnd, $hRefreshTimer) DllCallbackFree($pUpdateFunction) GUIDelete($hWnd) EndFunc Func _UpdateUI() ;Update the UI elements Local $speed = ($nLoops / $nRefreshRateMs) * 1000 $nLoops = 0 GUICtrlSetData($hLabel, $sLabelData & @CRLF & @CRLF & "Processing: " & _FormatSize(($nTransfered / $nRefreshRateMs) * 1000) & "/s") $nTransfered = 0 GUICtrlSetData($hSpeedLabel, "Hz = " & $speed & @CRLF & "Blocking function loop time: " & _FormatTime(TimerDiff($hProcessTimer)) & @CRLF & @CRLF & "Runtime: " & _FormatTime(TimerDiff($hElapsedTime))) EndFunc ; These functions are just for asthetic, and Otherwise irrelevant Func _FormatTime($nTime) Local $sReturn = "", $Temp if $nTime > 60000 Then $Temp = Int($nTime / 60000) $sReturn &= $Temp & "m " $nTime -= $Temp * 60000 EndIf $sReturn &= Int($nTime / 1000) & "s" Return $sReturn EndFunc Func _FormatSize($nBits) Local $sReturn = "" Local $nBitsInGibibyte = 8589934592, $nBitsInMebibyte = 8388608, $nBitsInKibibyte = 8192, $nBitsInByte = 8 Select Case $nBits > $nBitsInGibibyte $sReturn = Round($nBits / $nBitsInGibibyte, 1) & " GB" Case $nBits > $nBitsInMebibyte $sReturn = Round($nBits / $nBitsInMebibyte, 1) & " MB" Case $nBits > $nBitsInKibibyte $sReturn = Round($nBits / $nBitsInKibibyte) & " KB" Case Else $sReturn = ($nBits / $nBitsInByte & " B") EndSelect Return $sReturn EndFunc Edited November 16, 2021 by CYBRIX Link to comment Share on other sites More sharing options...
mLipok Posted November 16, 2021 Share Posted November 16, 2021 After 2 minutes runtime , I do not see any freezing with 1 single 4GB file. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
CYBRIX Posted November 17, 2021 Author Share Posted November 17, 2021 @mLipok In my testing I've observed the longest freezes happen when the script is finishing up large files and switching to a new file. Also, I am testing with an external 2.5' HDD. My suspicion so far is that the program freezes when waiting for the storage to respond. It would be sad if this is true, because that would mean that there is nothing that can be done to solve the issue. Did you use an SSD for your testing? (Thx all for taking time out of your days to help btw) Link to comment Share on other sites More sharing options...
CYBRIX Posted November 17, 2021 Author Share Posted November 17, 2021 Update: So I figured out that the FileClose() function brings everything to a halt (for up to 5 seconds at a time on the larger files I tested). I think this is the main culprit. Do you guys know of any way around this? Like maybe a way to hand the FileClose() function to windows, and proceed with the script while the function is being executed...? Or some other workaround. The thing is that I want to have control of the data being transferred, in order to be able to interrupt (Pause/Cancel) it and also calculate transfer speeds and such. This is why I didn't use FileCopy in the first place. Link to comment Share on other sites More sharing options...
mLipok Posted November 17, 2021 Share Posted November 17, 2021 (edited) 7 hours ago, CYBRIX said: Did you use an SSD for your testing? Yes SSD. 7 hours ago, CYBRIX said: Also, I am testing with an external 2.5' HDD. HDD on USB ? USB 3.x or 2.x ? 7 hours ago, CYBRIX said: In my testing I've observed the longest freezes happen when the script is finishing up large files and switching to a new file. So it happens when you close file handle. And this is relatead to: System , Disc, AV Software but not to AutoIt. Edited November 17, 2021 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
CYBRIX Posted November 17, 2021 Author Share Posted November 17, 2021 5 hours ago, mLipok said: HDD on USB ? USB 3.x or 2.x ? That would be USB 3.x. The utilization goes to and sticks at 99% during freezes. 5 hours ago, mLipok said: So it happens when you close file handle. And this is relatead to: System , Disc, AV Software but not to AutoIt. Ok. Essentially my idea now is to find a way to continue the script while FileClose() is being Executed... Hope that is possible, but my hopes are not too high, because even the _WinAPI-timers freeze... My thoughts: Handing it to a separate script (not pretty, and maybe not possible) Some ominous DLL or Windows workaround "Volatile" function keyword? (I don't actually know how this works yet) Anyone have Ideas? (Or corrections telling me I'm searching for the eighth dimension) Link to comment Share on other sites More sharing options...
mLipok Posted November 17, 2021 Share Posted November 17, 2021 (edited) 22 minutes ago, CYBRIX said: Essentially my idea now is to find a way to continue the script while FileClose() is being Executed. IMHO I think that this is NOT possible, because all what AutoIt does there is closing FileHandle, and the entire problem is strictly WindowsAPI + ComputerHardware (CPU+Drive) Performace, especially when AV software is watching file system in the background. unless.... 22 minutes ago, CYBRIX said: Handing it to a separate script (not pretty, and maybe not possible) This way should be possible with IPC UDF. Edited November 17, 2021 by mLipok CYBRIX 1 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Nine Posted November 17, 2021 Share Posted November 17, 2021 One solution would be to use the overlapped feature of the winapi related to files. https://docs.microsoft.com/en-us/windows/win32/sync/synchronization-and-overlapped-input-and-output This would be the proper way to async your file copy. Although it is not obvious... CYBRIX 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 Link to comment Share on other sites More sharing options...
Zedna Posted November 17, 2021 Share Posted November 17, 2021 (edited) Look at FileFlush() You can flush file buffer to disk more frequently (if there are more FileWrites) and each of them including final FileClose() will take shorter time ... Edited November 17, 2021 by Zedna mLipok and CYBRIX 2 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
mLipok Posted November 17, 2021 Share Posted November 17, 2021 (edited) 1 hour ago, Zedna said: You can flush file buffer to disk more frequently This should do the trick. I hope. Edited November 17, 2021 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
CYBRIX Posted November 19, 2021 Author Share Posted November 19, 2021 I didn't know about FileFlush() up until now, so that's a nice new thing to learn about, but unfortunately it either slows the transfer speeds down significantly, or also freezes, depending on how frequently it gets called. But thanks for the new knowledge @Zedna On 11/17/2021 at 9:23 AM, Nine said: One solution would be to use the overlapped feature of the winapi related to files. So, the _WinAPI_WriteFile() has a $tOverlapped parameter that requires "A $tagOVERLAPPED structure or a pointer to it" in order to use the overlapping feature. Does anyone know how to create said structure? I can't find any information on that. Or does it just use the handle from "_WinAPI_OpenFileById ( $hFile, $vID [, $iAccess = 0 [, $iShare = 0 [, $iFlags = $FILE_FLAG_OVERLAPPED]]] )" ? Link to comment Share on other sites More sharing options...
LarsJ Posted November 19, 2021 Share Posted November 19, 2021 The easy standard solution to such a problem is to execute the blocking/lengthy code in a separate process. Start a new process from your main program to perform the file operations. When the file operations run in a separate process, they'll no longer block the main program. Send a message from the new process back to the main program when the file operations are complete. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
mLipok Posted November 19, 2021 Share Posted November 19, 2021 (edited) 2 hours ago, CYBRIX said: I didn't know about FileFlush() up until now, so that's a nice new thing to learn about, but unfortunately it either slows the transfer speeds down significantly, or also freezes, depending on how frequently it gets called This is still related to my statement from here: On 11/17/2021 at 3:42 PM, mLipok said: because all what AutoIt does there is closing FileHandle, and the entire problem is strictly WindowsAPI + ComputerHardware (CPU+Drive) Performace, especially when AV software is watching file system in the background. THIS IS HOW I UNDERSTAND THIS (sorry for my poor English and lack of IT knowledge about how System Windows and Hardware behaves internally) When you copy files at the end when FileHandle is closing or when you use FileFlush() system is releasing data to all system processes, they are physically wrtie to each block on the disc area where the fiele will be stored. Then each system procecesses, including AV software, wants to diagnose them, and till all these processes works on this files, as so far you will not get back to AutoIt runtime main loop. In the other words, FileClose() and FileFlush() it transfers its CPU time (AutoIt CPU time) to the system as long as it takes to complete a given system operation. 2 hours ago, CYBRIX said: but unfortunately it either slows the transfer speeds down significantly, or also freezes, depending on how frequently it gets called. This is quite resonable or even obviuos. In total, you cannot speed up the operation (flusing to disc). You can only break the process into tiny pieces so that the end user doesn't see the process stop. ps. Interesting example I test it and work on it .... of course on similar "USB+HDD environment". Edited November 19, 2021 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
mLipok Posted November 19, 2021 Share Posted November 19, 2021 @LarsJ you mean just like I said here: On 11/17/2021 at 3:42 PM, mLipok said: unless.... On 11/17/2021 at 3:24 PM, CYBRIX said: Handing it to a separate script (not pretty, and maybe not possible) This way should be possible with IPC UDF. If so thanks for clarification. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Solution mLipok Posted November 19, 2021 Solution Share Posted November 19, 2021 @CYBRIX please check this: expandcollapse popup; Example script #include <File.au3> #include <GUIConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPISys.au3> Opt("GUIOnEventMode", 1) ;GUIOnEventMode = Yes Opt("MustDeclareVars", 1) ;Window properties Global Const $nWidth = 500, $nHeight = 200 Global Const $nRefreshRate = 25, $nRefreshRateMs = 1000 / $nRefreshRate Global $STATE = 0 Global Const $ST_END = -1 Global $sSelectedFolder ;Prompt for folder Do $sSelectedFolder = FileSelectFolder("Select a folder with a few files in it", @UserProfileDir & "\Documents") If @error Then Exit MsgBox(0, "Bye now", "Ended program.") Until FileExists($sSelectedFolder) ;Ensure I am not liable If MsgBox(49 + 256, "Warning", "This script clones the folder you selected (in the same directory)." & @CRLF & "It copys and deletes files until you stop it." & @CRLF & @CRLF & "I advise you not to proceed if you selected a folder on an SSD." & @CRLF & "I'M NOT RESPONSABLE FOR REDUCED SSD LIFE TIMES!") <> 1 Then Exit ;List files in folder Global $aFiles = _FileListToArrayRec($sSelectedFolder, "*", 13) If Not IsArray($aFiles) Or $aFiles[0] = 0 Then Exit MsgBox(16, "Bad pick", "It would seem the folder is empty." & @CRLF & "Ended Program.") ;Some variables Global Const $hElapsedTime = TimerInit() Global Const $nBlockSize = 1024 * 1024 Global $nTransfered = 0, $hProcessTimer Global $sLabelData = "Not yet updated", $nLoops Global $aDirCreated[2] = [False, ""] ;GUI Elements Global Const $hWnd = GUICreate("Freeze Example", $nWidth, $nHeight) Global Const $hLabel = GUICtrlCreateLabel($sLabelData, 10, 10, $nWidth - 20, $nHeight - 60) Global Const $hSpeedLabel = GUICtrlCreateLabel("", 10, $nHeight - 60, $nWidth - 20, 50) GUISetOnEvent($GUI_EVENT_CLOSE, _Close) GUISetState(@SW_SHOW, $hWnd) ;Let windows update UI elements ;~ Global Const $pUpdateFunction = DllCallbackRegister(_UpdateUI, "none", "") ;~ Global Const $hRefreshTimer = _WinAPI_SetTimer($hWnd, 0, $nRefreshRateMs, DllCallbackGetPtr($pUpdateFunction)) OnAutoItExitRegister(_EndScript) ;Ensure everything is closed properly ;Main Loop ;~ While $STATE <> $ST_END For $i = 1 To $aFiles[0] $hProcessTimer = TimerInit() _BlockingFunction($aFiles[$i], $sSelectedFolder, $sSelectedFolder & " (Copy)", $i & ' / ' & $aFiles[0]) ;The blocking function Next ;~ WEnd Exit Func _BlockingFunction($sFileName, $sSource, $sDestination, $s_FileProgress) ;Clone the selected folder Local $sData, $nError If Not $aDirCreated[0] And FileExists($sDestination) Then Do $sDestination &= " (Copy)" Until Not FileExists($sDestination) EndIf DirCreate($sDestination) $aDirCreated[0] = True $aDirCreated[1] = $sDestination $sDestination &= "\" & $sFileName If FileExists($sDestination) Then FileDelete($sDestination) _FileCreate($sDestination) Local $hCurrentSource = FileOpen($sSource & "\" & $sFileName, 16) Local $hCurrentDest = FileOpen($sDestination, 1) $sLabelData = ' File: ' & $s_FileProgress & " ... Copying: ...\" & $sFileName Do $sData = FileRead($hCurrentSource, $nBlockSize) $nError = @error FileWrite($hCurrentDest, $sData) $nLoops += 1 If $nError = -1 Then ; if EOF $nTransfered += StringLen($sData) ExitLoop EndIf $nTransfered += $nBlockSize _UpdateUI() Until $STATE = $ST_END Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. FileClose($hCurrentSource) FileClose($hCurrentDest) Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff. ConsoleWrite("! Saved: " & $sFileName & ' ...... in ' & $fDiff & ' mili seconds' & @CRLF) EndFunc ;==>_BlockingFunction Func _Close() $STATE = $ST_END EndFunc ;==>_Close Func _EndScript() If $aDirCreated[0] And MsgBox(36, "Delete created folder?", "Do you want to delete " & $aDirCreated[1] & "?" & @CRLF & "(No, that is not the original. But do double check.)") = 6 Then $sLabelData = "Removing: " & $aDirCreated[1] If DirRemove($aDirCreated[1], 1) = 0 Then MsgBox(16, "Error", "Failed to remove: " & $aDirCreated[1] & @CRLF & "Guess you'll have to do that. sry...") Else MsgBox(0, "Success", "Folder was removed.") EndIf EndIf ;~ _WinAPI_KillTimer($hWnd, $hRefreshTimer) ;~ DllCallbackFree($pUpdateFunction) GUIDelete($hWnd) EndFunc ;==>_EndScript Func _UpdateUI() ;Update the UI elements Local $speed = ($nLoops / $nRefreshRateMs) * 1000 $nLoops = 0 GUICtrlSetData($hLabel, $sLabelData & @CRLF & @CRLF & "Processing: " & _FormatSize(($nTransfered / $nRefreshRateMs) * 1000) & "/s") $nTransfered = 0 GUICtrlSetData($hSpeedLabel, "Hz = " & $speed & @CRLF & "Blocking function loop time: " & _FormatTime(TimerDiff($hProcessTimer)) & @CRLF & @CRLF & "Runtime: " & _FormatTime(TimerDiff($hElapsedTime))) EndFunc ;==>_UpdateUI ; These functions are just for asthetic, and Otherwise irrelevant Func _FormatTime($nTime) Local $sReturn = "", $Temp If $nTime > 60000 Then $Temp = Int($nTime / 60000) $sReturn &= $Temp & "m " $nTime -= $Temp * 60000 EndIf $sReturn &= Int($nTime / 1000) & "s" Return $sReturn EndFunc ;==>_FormatTime Func _FormatSize($nBits) Local $sReturn = "" Local $nBitsInGibibyte = 8589934592, $nBitsInMebibyte = 8388608, $nBitsInKibibyte = 8192, $nBitsInByte = 8 Select Case $nBits > $nBitsInGibibyte $sReturn = Round($nBits / $nBitsInGibibyte, 1) & " GB" Case $nBits > $nBitsInMebibyte $sReturn = Round($nBits / $nBitsInMebibyte, 1) & " MB" Case $nBits > $nBitsInKibibyte $sReturn = Round($nBits / $nBitsInKibibyte) & " KB" Case Else $sReturn = ($nBits / $nBitsInByte & " B") EndSelect Return $sReturn EndFunc ;==>_FormatSize What results to the console gives you this following line: ConsoleWrite("! Saved: " & $sFileName & ' ...... in ' & $fDiff & ' mili seconds' & @CRLF) ?? CYBRIX 1 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
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