0

I have some code that reads from an ini file in Javascript, using activex filesystem objects.

This isn't particularly efficient but does the job, reading the whole file into an array, appending any changes and writing back.

The problem i'm having is that another process, a C# XBAP application is reading from this ini file (using getprivateprofilestring) at the same time as I could potentially be trying to write to it in the JS.

The javascript fails as the file is locked, or part of it, and the file ends up getting corrupted or even totally cleared - as I am trying to write back the whole file each time.

Preferably, what I need is a way to determine if a file is locked in javascript, as the writes are not urgent and I want to let any reads finish first.

Just can't seem to find anyway of syncing these two completely seperate ways of accessing the file.

2
  • Can you post your JS code, and maybe the C# too? Commented Nov 29, 2010 at 10:27
  • There is no problem from JS side. Consider fixing other side by avoiding GetPrivateProfileString Commented Nov 29, 2010 at 10:39

1 Answer 1

1

May be you could use try/catch. If you open the file for appending (OpenTextFile([filename],8)) it should raise an exception. Same should be true for writing/saving the file (if the file is locked try raises an exception).

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah I am thinking of doing something like that, the problem is it appears to be to late by that point as the file is already truncated. I wonder if I opened the file first for appending, tried to write a line and if that failed I could abort the whole following write operation, that could work maybe?
Ok, unfortunately the append doesn't seem to fail, only the normal write. It seems that only a specific section of the file is locked, not the whole thing? I'm not really sure how getprivateprofile string handles it's file locking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.