public ProcessItem(Process process, string name, int id, long memory, int priority, ProcessThreadCollection threads) { this.process = process; this.name = name; this.id = id; this.memory = memory; this.threads = threads; this.priority = priority; this.isKeepingAlive = false; this.args = this.getArguments(); }
public static long getThreadTotalCpuTime0(long id) { if (id == 0) { int currentId = GetCurrentThreadId(); System.Diagnostics.ProcessThreadCollection threads = System.Diagnostics.Process.GetCurrentProcess().Threads; foreach (System.Diagnostics.ProcessThread t in threads) { if (t.Id == currentId) { return((long)(t.TotalProcessorTime.Ticks * 100)); } } return(0); } else { throw new System.NotImplementedException("Only current Thread is supported."); } }
//____________________________________________________________________________ //Display thread info. //called by DealWithThreadsForTesting private string DealWithNewThreads() { StringBuilder sb = new StringBuilder(); bool newThreadChecker = false; lock (this.lockerForThreadHashSet) { // if (managedThreadIds.Add(Thread.CurrentThread.ManagedThreadId) == true) // { // managedThreads.Add(Thread.CurrentThread); // newThreadChecker = true; // } } if (newThreadChecker == true) { //Display system threads //Note that there is NOT a 1:1 ratio between managed threads //and system (native) threads. sb.Append("\r\n**** New managed thread. Threading info:\r\nSystem thread numbers: "); arrayOfLiveThreadsInThisProcess = theProcess.Threads; //for testing only foreach (ProcessThread theNativeThread in arrayOfLiveThreadsInThisProcess) { sb.Append(theNativeThread.Id.ToString() + ", "); } //Display managed threads //Note that there is NOT a 1:1 ratio between managed threads //and system (native) threads. sb.Append("\r\nManaged threads that have been used: "); // foreach (Int32 theManagedThreadId in managedThreadIds) // { // sb.Append(theManagedThreadId.ToString() + ", "); // } //Managed threads above were/are being used. //Managed threads below are still being used now. sb.Append("\r\nManagedthread.IsAlive true: "); // foreach (Thread theManagedThread in managedThreads) // { // if (theManagedThread.IsAlive == true) // { // sb.Append(theManagedThread.ManagedThreadId.ToString() + ", "); // } // } sb.Append("\r\nEnd thread info."); } return sb.ToString(); }
/// <summary> /// List the titles of visible windows to <c>Console</c>. /// </summary> /// <remarks>This function is used to write configuration files.</remarks> /// <param name="threads">A collection of threads</param> static private void listVisibleWindowsTitle(ProcessThreadCollection threads) { foreach (ProcessThread t in threads) User32.EnumThreadWindows(t.Id, (IntPtr winHandle, IntPtr param) => { if (!User32.IsWindowVisible(winHandle)) return true; // Gets the window title: int len1 = User32.GetWindowTextLength(winHandle); if (len1 == 0) throw new ApplicationException("Could not get window text length. Error code: " + User32.GetLastError()); StringBuilder buffer = new StringBuilder(len1 + 1); int len2 = User32.GetWindowText(winHandle, buffer, len1 + 1); if (len2 == 0) throw new ApplicationException("Could not get window text. Error code: " + User32.GetLastError()); if (len1 != len2) throw new ApplicationException("Lengths should match (" + len1 + " != " + len2 + ")"); Console.WriteLine(buffer); return true; }, IntPtr.Zero); }
/// <summary> /// Find windows for a thread collection. /// </summary> /// <para> /// Only the windows matching the given title are returned. /// </para> /// <param name="threads">A collection of threads</param> /// <param name="title">A regexp to select windows according to their title</param> /// <returns></returns> static private List<IntPtr> findVisibleWindows(ProcessThreadCollection threads, string title) { List<IntPtr> ret = new List<IntPtr>(); foreach (ProcessThread t in threads) User32.EnumThreadWindows(t.Id, (IntPtr winHandle, IntPtr param) => { if (!User32.IsWindowVisible(winHandle)) return true; // Gets the window title: int len1 = User32.GetWindowTextLength(winHandle); if (len1 == 0) throw new ApplicationException("Could not get window text length. Error code: " + User32.GetLastError()); StringBuilder buffer = new StringBuilder(len1 + 1); int len2 = User32.GetWindowText(winHandle, buffer, len1 + 1); if (len2 == 0) throw new ApplicationException("Could not get window text. Error code: " + User32.GetLastError()); if (len1 != len2) throw new ApplicationException("Lengths should match (" + len1 + " != " + len2 + ")"); // Check if it matches: Regex regexp = new Regex(title); if (regexp.IsMatch(buffer.ToString())) ret.Add(winHandle); return true; }, IntPtr.Zero); return ret; }
private void MostrarHilos(ProcessThreadCollection colección, TextWriter output) { foreach (ProcessThread thread in colección) output.WriteLine("\t- ThreadId: {0}\tPrioridad: {1}\tEstado: {2}.", thread.Id, thread.CurrentPriority, thread.ThreadState); }
public void Refresh() { this.processInfo = null; this.threads = null; this.modules = null; this.mainWindowTitle = null; this.exited = false; this.signaled = false; this.haveMainWindow = false; this.haveWorkingSetLimits = false; this.haveProcessorAffinity = false; this.havePriorityClass = false; this.haveExitTime = false; this.haveResponding = false; this.havePriorityBoostEnabled = false; }
/// <devdoc> /// <para> /// Discards any information about the associated process /// that has been cached inside the process component. After <see cref='System.Diagnostics.Process.Refresh'/> is called, the /// first request for information for each property causes the process component /// to obtain a new value from the associated process. /// </para> /// </devdoc> public void Refresh() { _processInfo = null; _threads = null; _modules = null; _exited = false; _haveWorkingSetLimits = false; _haveProcessorAffinity = false; _havePriorityClass = false; _haveExitTime = false; _havePriorityBoostEnabled = false; RefreshCore(); }