diff --git a/WebPortal+Email+Log.mm b/WebPortal+Email+Log.mm index d6acdcd449..b58aa45641 100644 --- a/WebPortal+Email+Log.mm +++ b/WebPortal+Email+Log.mm @@ -200,9 +200,13 @@ -(void)updateLogEntryForStudy:(DicomStudy*)study withMessage:(NSString*)message { if ([[NSUserDefaults standardUserDefaults] boolForKey: @"logWebServer"] == NO) return; -// [self.dicomDatabase.managedObjectContext lock]; - - DicomDatabase* independentDatabase = self.dicomDatabase.independentDatabase; + DicomDatabase* independentDatabase = nil; + + if( [NSThread isMainThread]) + independentDatabase = self.dicomDatabase; + else + independentDatabase = self.dicomDatabase.independentDatabase; + @try { if (user) message = [user stringByAppendingFormat:@": %@", message]; @@ -213,7 +217,6 @@ -(void)updateLogEntryForStudy:(DicomStudy*)study withMessage:(NSString*)message // Search for same log entry during last 5 min NSArray* logs = NULL; - NSPredicate* predicate = [NSPredicate predicateWithFormat: @"(patientName==%@) AND (studyName==%@) AND (message==%@) AND (originName==%@) AND (endTime >= CAST(%lf, \"NSDate\"))", study.name, study.studyName, message, ip, [[NSDate dateWithTimeIntervalSinceNow: -5 * 60] timeIntervalSinceReferenceDate]]; logs = [independentDatabase objectsForEntity:independentDatabase.logEntryEntity predicate:predicate];