/// <summary> /// Init constructor of DebugViewData. /// </summary> public DebugViewData(uint pid, string message) { this.pid = pid; this.message = message; creation = DateTime.Now; ProcessData dbgProcess = ProcessDataCache.GetByID(pid); if (dbgProcess != null) { processName = dbgProcess.Name; processPath = dbgProcess.MainModuleFileName; } }
/// <summary> /// Get description for process with given PID. /// </summary> public static ProcessData GetByID(uint pid) { ProcessData result; lock (syncLock) { // check if last query wanted the same PID: if (pid == lastInfo.PID) { result = lastInfo; } else { // check internal collection: if (infos.TryGetValue(pid, out result)) { lastInfo = result; } else { // when all failed, ask the OS and add to caches: try { Process process = Process.GetProcessById((int)pid); if (process != null) { result = new ProcessData(pid, process.ProcessName, (process.MainModule != null ? process.MainModule.FileName : UnknownModuleFileName)); lastInfo = result; infos.Add(pid, result); } else { result = UnknownProcess; } } catch { result = UnknownProcess; } } } } return(result); }
/// <summary> /// Process received message. /// </summary> static void SourceDataReceived(IDbgSource source, uint pid, string message) { lock (syncItems) { DateTime creation = DateTime.Now; string[] msgs; if (string.IsNullOrEmpty(message)) { msgs = new string[] { string.Empty }; } else { message = message.Replace("\t", TabReplace); msgs = message.Replace("\r\n", "\r").Replace("\n", "\r").Split('\r'); } // check if this element has already the name: if (pid == 0 && (!string.IsNullOrEmpty(source.Name) || !string.IsNullOrEmpty(source.Module))) { foreach (string m in msgs) { storedItems.Enqueue(new DebugViewData(0, source.Name, source.Module, creation, m.TrimEnd(null))); } } else { ProcessData dbgProcess = ProcessDataCache.GetByID(pid); if (dbgProcess != null) { foreach (string m in msgs) { storedItems.Enqueue(new DebugViewData(pid, dbgProcess.Name, dbgProcess.MainModuleFileName, creation, m.TrimEnd(null))); } } } // avoid data flooding, by adding 1-sec delays // when sending to the receiver: if (!isRefreshing) { isRefreshing = true; refreshTimer.Change(1000, Timeout.Infinite); } } }