Hi All
I seem to be having a problem with this code below, I can run the Below code 100 times and it runs fine, If i close the window and reopen the window i then get ErrorCode 90 with FileError reading Error Access Violation: CLARUN.dll
The only way to stop getting the fault is to close the program and restart, then it will work again for as long as that window stays open. Closing and Opening the window does start a new thread
This code is called from multiple windows and behaves the same way on all windows, 1st thread works perfectly , 2nd thread gets the error
I have only left the error check in where i am getting the Fault
**Data**
OpenJobs FILE,DRIVER('BASIC'),NAME(SourceName),PRE(CSV),CREATE
Record RECORD
cLine1 CString(300)
cLine2 CString(300)
END
End
**Code**
If Exists(SourceName)
Remove(SourceName)
End
Create(OpenJobs)
If ErrorCode() = 90
STR.Trace(FileError() &' '&FileErrorCode())
End
Open(OpenJobs)
Stream(OpenJobs)
CSV:cLine1 = 'Open Jobs'
CSV:cLine2 = 'Vehicle Reg'
Add(OpenJobs)
Flush(OpenJobs)
Close(OpenJobs)
The error 90 is odd, and even more so the “Access Violation” is a memory access error.
This code is running on multiple Threads but the file does Not have the THREAD attribute. That is probably the cause, that its in the middle of Window 1 updating the file when another thread gets a time slice and tries to use that same file. The state of the file control block is bad.
So add THREAD to OpenJobs file, and to SourceName if it changes for each window.
As Jeff said after CREATE() you need to check for all errors not just 90. Since you OPEN(OpenJobs) the file is opened for exclusive use (Deny All) so others trying to access it will get an Error 5 Access Denied.
These are documented errors:
CASE ERRORCODE()
OF NoError !0 No Error Occured
OF NoPathErr !3 Path Not Found
OF TooManyErr !4 Too Many Open Files
OF NoAccessErr !5 Access Denied
OF IsOpenErr !52 File Already Open
OF NoCreateErr !54 No Create Attribute
OF FileSystemErr !90 File System Error
CASE FILEERRORCODE()
ELSE
STOP('File Error: '&FILEERRORCODE()&'-'&CLIP(FILEERROR()) &|
'<13,10>'&CLIP(ERRORFILE()))
END !CASE FileError
ELSE
STOP('Error: '&ERRORCODE()&'-'&CLIP(ERROR()) &|
'<13,10>'&CLIP(ERRORFILE()) &|
'<13,10>'&FILEERRORCODE()&'-'&CLIP(FILEERROR()))
END !CASE Error
I have seen CREATE() return Error 2 File Not Found on a network. Repeating the CREATE() worked so I usually include it.
Thank you for all the responses.
I tried most of the above recommendations and couldn’t seem to get it to go back to working.
In terms of the error checking, i had the full error check in my actual code i just shortened it to not complicate the code posted.
I eventually used StringTheory which seems to be working as required.
Thank you for the help