ssCore.BinaryFile.lock

Obtain an exclusive lock on the file.


Availability:

First available in version 3.7 build 197.


Input Parameters:

None.


Output Parameters:

systemError - A system specific error code from the GetLastError function.


Asynchronous Mode:

When this method is called asynchronously, a return object containing the output parameters is passed to the specified callback function.

ssCore.BinaryFile.lock( paramsObject [, callbackParamsObject] [, errorParamsObject] );


Synchronous Mode:

When this method is called synchronously, a return object containing the output parameters is returned to the caller immediately.

var returnObject = ssCore.BinaryFile.lock( paramsObject );


Notes:

Gives you, the locking process, exclusive access to the file until you release the lock by calling the unlock function. An exclusive lock denies all other processes both read and write access to the file.

                

Examples:

Create a new file and attempt to lock it for exclusive access to prevent other processes from accessing it while we work with it.

ssCore.BinaryFile.create({path:"startdir://test.dat", accessMode:"write", failIfExists:"false"});

var r:Object = ssCore.BinaryFile.lock({});

if (r.success)
{
    ssCore.BinaryFile.writeBytes({data:"i am the data", format:"utf8"});
    // we must unlock the file before closing it, or the call to close will fail.
    ssCore.BinaryFile.unlock({});
}

ssCore.BinaryFile.close({});