tremolux66 Posted September 28, 2016 Posted September 28, 2016 (edited) I've run into the problem where multiple script processes writing to a log file at the same time can interfere with one another. That is, file writes using FileWriteLine are not atomic, so a line of text from one process can have fragments of text from other processes mixed in with it. Exclusive file-locking should take care of the problem. Looking through the standard UDFs, I see that _WinAPI_LockFile is available, but according to the MSDN documentation it doesn't block - it returns immediately if the lock can't be obtained - and there doesn't seem to be a UDF for the LockFileEx function. I considered writing my own UDF for LockFileEx, but some aspects (e.g., creating the OVERLAPPED structure and its members) look too complex for the amount of time I have available. I think approximating LockFileEx using LockFile could solve my problem, but I'd like to keep it simple while still working reliably. I'm not confident that (e.g.) a simple retry loop to simulate blocking will be adequate. Any suggestions for a simple way to achieve exclusive file-locking with blocking? Edited September 30, 2016 by tremolux66 Mark problem as solved When the going gets tough, the tough start coding.
orbs Posted September 28, 2016 Posted September 28, 2016 this is what you're looking for: i have used it successfully in a very much similar scenario to yours. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
tremolux66 Posted September 28, 2016 Author Posted September 28, 2016 (edited) Thanks, I'll give that a try! Edited September 28, 2016 by tremolux66 Typo When the going gets tough, the tough start coding.
tremolux66 Posted September 30, 2016 Author Posted September 30, 2016 Works great - problem solved! All the log messages are stored perfectly. When the going gets tough, the tough start coding.
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