Hi guys,
I created a sample multithreaded application to test concurrent execution of my CSV file writers and parsing of this file by LogParser. When the CSV file grew (>5Mb) the application started to produce errors "The process cannot access the file 'c:\jobclicks.csv' because it is being used by another process." The errors are generated by my code which writes to file. Writer threads works well alone, but when i enable concurrent reading by LogParser the errors are produced again.
Does it mean that LogParser locks files when it parses them? I think it is very bad if is it true.
Could someone comment this behaviour?
P.S. applciation is written used C#, .net framework 3.0
CSV Writer code:
using (FileStream fs = new FileStream(logFileName, FileMode.Append, FileAccess.Write, FileShare.Read)) // <<<------- exception there
{
using (CsvWriter w = new CsvWriter(fs, charDelimiter, logFileEncoding))
{
w.WriteRecord(new string[] {"DateTime", "JobId", "JobSiteId", "IP", "ThreadId"});
}
}
Parser code:
// Instantiate the LogQuery object
LogQueryClassClass logQuery = new LogQueryClassClass();
// Instantiate the Event Log Input Format object
COMCSVInputContextClassClass inputFormat = new COMCSVInputContextClassClass();
// Execute the query
ILogRecordset rs = logQuery.Execute(
String.Format(@"SELECT JobSiteId, COUNT(1) FROM '{0}' GROUP BY JobSiteId", logFileName), inputFormat);
try
{
// Browse the recordset
for (; !rs.atEnd(); rs.moveNext())
{
ILogRecord r = rs.getRecord();
int jobSiteId = (int)r.getValue(0);
int count = (int)r.getValue(1);
result.Add(jobSiteId, count);
}
}
finally
{
rs.close();
}