/// <summary> /// Adds a new instance session /// </summary> public void AddNewInstanceSession(UInt32 processId, DateTime startDate) { if (InstanceSessions.Exists(ins => (ins.IsActive) && (ins.SystemProcessId == processId))) // Guard condition { // Theoretically this block should never be entered. If it is it means that there is more than one instance of the // exe with the SAME processId running concurrently. This would probably mean that the first one was never closed. Console.WriteLine("Problem: Tried to register a new exe instance session, but another with the same processId was already running?!"); return; } InstanceSessions.Add(new ProgramInstanceSession(processId, startDate)); NumActiveInstances++; }
/// <summary> /// Ends an instance session /// </summary> public void EndInstanceSession(UInt32 processId, DateTime endTime) { ProgramInstanceSession pis = InstanceSessions.Find(ins => (ins.IsActive) && (ins.SystemProcessId == processId)); if (pis == null) // Guard condition { Console.WriteLine("Problem: Tried to close an exe instance session, but it couldn't find it!"); return; } pis.EndSession(endTime); NumActiveInstances--; if (!IsActive) { RegisterEndOfSession(); } }