DrLarch Posted April 26, 2019 Share Posted April 26, 2019 (edited) I've been having trouble with a section of my script that waits for a process. While waiting, even though the process still exists, my script sometimes exits, particularly on computers where the process takes longer than other faster machines. I know this because my code logs its progress to a file as it runs. The section I've narrowed it down to is this: Do Sleep(5000) Until Not ProcessExists("sfc.exe") I initially was using RunWait to wait for the process to end, but that was sometimes failing on slower machines. So I tried a Do Until loop and then a While WEnd loop just to see if it made a difference. I know I could have used Run and ProcessWaitClose but am trying to minimize its performance impact (only checking periodically instead of more frequently). I've watched my Autoit executable as it runs, and have noticed odd behavior regarding memory usage. It starts out with greater than 20mb of memory and as sfc.exe runs, my Autoit exe memory usage steadily drops until around 1mb, after which it unexpectedly quits. Here's a log to show how the memory usage drops as it runs: 11:28 - 23,096 K 11:29 - 20,468 K 11:30 - 19,752 K 11:31 - 17,912 K 11:32 - 16,588 K 11:33 - 11,724 K 11:34 - 8,496 K 11:35 - 6,764 K 11:36 - 5,056 K 11:37 - 3,688 K 11:38 - 2,620 K 11:39 - 1,916 K 11:40 - 1,468 K 11:41 - 1,228 K I've worked around this issue by checking less frequently (increasing sleep). But it still seems to be a balancing game with the process check frequency or a race to try to make sure the script finishes before it runs too long and dumps out. But don't think I should have to do this if RunWait was working correctly in the first place. I'm running Autoit v3.3.14.2, so thought I'd check the release notes for a newer version to see if this issue was addressed but didn't see anything related. Regardless, I upgraded to the current version v3.3.14.5, recompiled and am still experiencing the same behavior. I've attached the full au3. The section in question is around lines 452 to 469. Any advice is appreciated. WeeklyCleanup.au3 Edited April 26, 2019 by DrLarch Link to comment Share on other sites More sharing options...
Nine Posted April 26, 2019 Share Posted April 26, 2019 You don't use RunWait in your WeeklyCleanup and you don't show the code neither in your snippet. But I would guess that you do not check for any kind of error after the RunWait. I suggest you fully test the exit code AND the @error after RunWait is completed. You may learn what is causing the premature exit... “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...
DrLarch Posted April 26, 2019 Author Share Posted April 26, 2019 As I mentioned in my first post, I did use RunWait initially. I'm checking for an error on that. That said, I tried compiling it as a console app and running it that way (and changed the _Log function to do ConsoleWrites instead). This way the memory isn't dropping and it's running fine which is weird. So now I'm having to chase it down a different rabbit hole. I'll update when I figure out more. Link to comment Share on other sites More sharing options...
DrLarch Posted April 29, 2019 Author Share Posted April 29, 2019 Ok, I tried many different ways of pulling the exit code, both with RunWait and in a loop using If Not ProcessExists(ExitLoop) after just the Run function. Never caught any @error code, the script just quit. 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