public R WithContext <R>(ActorItem self, ActorItem parent, ProcessId sender, ActorRequest request, object msg, Option <SessionId> sessionId, Func <R> f) { var savedContext = ActorContext.Request; var savedSession = ActorContext.SessionId; try { ActorContext.SessionId = sessionId; ActorContext.SetContext( new ActorRequestContext( this, self, sender, parent, msg, request, ProcessFlags.Default, Settings.TransactionalIO ? ProcessOpTransaction.Start(self.Actor.Id) : null)); return(f()); } catch (Exception e) { logErr(e); throw; } finally { ActorContext.SessionId = savedSession; ActorContext.SetContext(savedContext); } }