This project is read-only.
1

Resolved

possible race condition ?

description

Is it possible that between check logFileWrite==null en lock(logFileWriter), logFileWriter can become null ?
   void writeMessages(TraceMessage[] TraceMessages) {
      if (logFileWriter==null) return; //logFileWriter is disposed

      lock(logFileWriter){ // here a null object reference exception occurred
       foreach (TraceMessage traceMessage in TraceMessages) {
          if (filter!=null && filter(traceMessage)) continue;

          logFileWriter.WriteMessage(traceMessage.ToString()); // here null object reference exception occurred
        }
While debugging I encountered a null object reference exception on logFileWriter.WriteMessage
and also once on the lock statement ... maybe it would be better to lock a different object than the logFileWriter ?

comments

PeterHuberSg wrote Feb 16 at 11:02 AM

I solved the problem like this in version 1.1:
  LogFileWriter wasLogFileWriter = logFileWriter;
  if (wasLogFileWriter==null) return; //logFileWriter is disposed

  lock(wasLogFileWriter) {
    foreach (TraceMessage traceMessage in TraceMessages) {
      if (filter!=null && filter(traceMessage)) continue;

      wasLogFileWriter.WriteMessage(traceMessage.ToString());
    }
  }