private void thread_Click(object sender, EventArgs e) { Process procces = Process.GetCurrentProcess(); ProcessThreadCollection threadCollection = procces.Threads; string threads = string.Empty; foreach (System.Diagnostics.ProcessThread proccessThread in threadCollection) { threads = string.Format("Thread Id: {0}, ThreadState: {1}\r\n", proccessThread.Id, proccessThread.ThreadState); list_Box_R.Items.Add(threads); } }
private void ProccessList_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { Process b = (Process)ProccessList.SelectedItem; ProcessThreadCollection c = b.Threads; ThreadsList.ItemsSource = c; } catch (Exception ex) { ErrorOrSuccesTex.Text += ex; } }
public static void threadSuper() { ProcessThreadCollection threads = Process.GetCurrentProcess().Threads; foreach (ProcessThread pt in threads) { //Console.WriteLine(" thread: {0}", pt.Id); //Console.WriteLine(" started: {0}", pt.StartTime.ToString()); //Console.WriteLine(" CPU time: {0}", pt.TotalProcessorTime); //Console.WriteLine(" priority: {0}", pt.BasePriority); //Console.WriteLine(" thread state: {0}", pt.ThreadState.ToString()); } }
public static void SuspendProcess(Process process) { if ((process == null) || (process.HasExited)) { return; } ProcessThreadCollection collection = process.Threads; foreach (ProcessThread thread in collection) { ThreadManager.SuspendThread(thread); } }
internal void RefreshInfo(Process process) { IsActive = !process.HasExited; // check PercentageCPU = new PerformanceCounter("Process", "% Processor Time", _nameProcess).NextValue(); CapacityRAM = new PerformanceCounter("Process", "Working Set", _nameProcess).NextValue(); // VirtualMemorySize64 NumberThread = process.Threads.Count; NameUser = process.MachineName; PathToFile = process.MainModule.FileName; StartDateTime = process.StartTime; Modules = process.Modules; // ModuleName and FileName Threads = process.Threads; // Id, стан, StartTime }
private Boolean MinersAreRunning() { Process[] allProcs = Process.GetProcesses(); foreach (Process proc in allProcs) { ProcessThreadCollection myThreads = proc.Threads; if (proc.ProcessName.ToLower().Contains("xmrig") || proc.ProcessName.ToLower().Contains("xmrminer")) { return(true); } } return(false); }
public async Task TestStartTimeProperty() { TimeSpan allowedWindow = TimeSpan.FromSeconds(2); using (Process p = Process.GetCurrentProcess()) { // Get the process' start time DateTime startTime = p.StartTime.ToUniversalTime(); // Get the process' threads ProcessThreadCollection threads = p.Threads; Assert.NotNull(threads); Assert.NotEmpty(threads); // Get the current time DateTime curTime = DateTime.UtcNow; // Make sure each thread's start time is at least the process' // start time and not beyond the current time. int passed = 0; foreach (ProcessThread t in threads.Cast <ProcessThread>()) { try { Assert.InRange(t.StartTime.ToUniversalTime(), startTime - allowedWindow, curTime + allowedWindow); passed++; } catch (InvalidOperationException) { // The thread may have gone away between our getting its info and attempting to access its StartTime } } Assert.InRange(passed, 1, int.MaxValue); // Now add a thread, and from that thread, while it's still alive, verify // that there's at least one thread greater than the current time we previously grabbed. await Task.Factory.StartNew(() => { p.Refresh(); try { var newest = p.Threads.Cast <ProcessThread>().OrderBy(t => t.StartTime.ToUniversalTime()).Last(); Assert.InRange(newest.StartTime.ToUniversalTime(), curTime - allowedWindow, DateTime.Now.ToUniversalTime() + allowedWindow); } catch (InvalidOperationException) { // A thread may have gone away between our getting its info and attempting to access its StartTime } }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); } }
/// <summary> /// Returns the list of thread id of all the threads of the current process /// </summary> /// <returns></returns> private List <int> GetCurrentThreadIds() { ProcessThreadCollection threadCollection = Process.GetCurrentProcess().Threads; IEnumerator e = threadCollection.GetEnumerator(); List <int> IdList = new List <int>(); while (e.MoveNext()) { ProcessThread pt = (ProcessThread)e.Current; IdList.Add(pt.Id); } return(IdList); }
public IEnumerable <ThreadModel> GetThreadsInfo(ProcessThreadCollection threads) { ICollection <ThreadModel> threadsInfo = new List <ThreadModel>(); for (int i = 0; i < threads.Count; i++) { ThreadModel model = new ThreadModel(); model.Id = threads[i].Id; model.Priority = threads[i].PriorityLevel.ToString(); threadsInfo.Add(model); } return(threadsInfo); }
// helper function for ReportMemoryStatus() public static int GetTotalRunningThreadCount() { try { Process proc = Process.GetCurrentProcess(); ProcessThreadCollection threads = proc.Threads; return(threads.Count); } catch (Exception ex) { Logging.Error(ex, "GetTotalRunningThreadCount() failed to deliver number of current running threads."); } return(0); }
public static ListViewItem[] GetThreadInfo(int index) { ProcessThreadCollection threads = processes[index].Threads; List <ListViewItem> listViewItems = new List <ListViewItem>(); for (int i = 0; i < threads.Count; i++) { ListViewItem temp = new ListViewItem(); temp.Text = threads[i].Id.ToString(); temp.SubItems.Add(threads[i].CurrentPriority.ToString()); listViewItems.Add(temp); } return(listViewItems.ToArray()); }
[PlatformSpecific(TestPlatforms.OSX)] // OSX throws PNSE from StartTime public void TestStartTimeProperty_OSX() { using (Process p = Process.GetCurrentProcess()) { ProcessThreadCollection threads = p.Threads; Assert.NotNull(threads); Assert.NotEmpty(threads); ProcessThread thread = threads[0]; Assert.NotNull(thread); Assert.Throws <PlatformNotSupportedException>(() => thread.StartTime); } }
/// <summary> /// Method returns an array containg the threads that a process is running. /// </summary> /// <param name="nProcID"> </param> public static ProcessThreadCollection GetProcessThreads(int nProcID) { try { Process proc = Process.GetProcessById(nProcID); ProcessThreadCollection threads = proc.Threads; return(threads); } catch (Exception) { //TheSystemMessageLog.ToCo(e.Message); return(null); } }
static void EnumerateThreads(Process[] processes) { foreach (Process process in processes) { try{ ProcessThreadCollection currentThreads = process.Threads; foreach (ProcessThread thread in currentThreads) { Console.WriteLine("{0} Thread: {1}", process.ProcessName, thread.Id); } } catch (Exception e) {} } }
public void TestStartAddressProperty() { using (Process p = Process.GetCurrentProcess()) { ProcessThreadCollection threads = p.Threads; Assert.NotNull(threads); Assert.NotEmpty(threads); IntPtr startAddress = threads[0].StartAddress; // There's nothing we can really validate about StartAddress, other than that we can get its value // without throwing. All values (even zero) are valid on all platforms. } }
private void button1_Click(object sender, EventArgs e) { Process procces = Process.GetCurrentProcess(); ProcessThreadCollection threadCollection = procces.Threads; string threads = string.Empty; foreach (ProcessThread proccessThread in threadCollection) { threads += string.Format("Thread Id: {0}, ThreadState: {1}\r\n", proccessThread.Id, proccessThread.ThreadState); } MessageBox.Show(threads); }
public static ProcessThread FetchThreadById(int id) { ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads; foreach (ProcessThread thread in currentThreads) { if (thread.Id.Equals(id)) { return(thread); } } return(null); }
private void ThreadsButton_Click(object sender, EventArgs e) { ProcessThreadCollection Threads = item.Threads; List <String> threadList = new List <string>(); for (int i = 0; i < Threads.Count; i++) { threadList.Add(Threads[i].Id.ToString()); } Form4 form4 = new Form4(threadList); form4.Show(); }
public static void TerminateProcess(Process process) { if ((process == null) || (process.HasExited)) { return; } ProcessThreadCollection collection = process.Threads; foreach (ProcessThread thread in collection) { ThreadManager.suspendedThreadsIdList.Remove(thread.Id); } process.Kill(); }
/// <summary>Retrieves the ProcessThread for the calling thread</summary> /// <returns>The ProcessThread for the calling thread</returns> internal static ProcessThread GetProcessThread(int threadId) { ProcessThreadCollection threads = Process.GetCurrentProcess().Threads; for (int index = 0; index < threads.Count; ++index) { if (threads[index].Id == threadId) { return(threads[index]); } } return(null); }
public void Refresh(Process process) { try { IsActive = process.Responding; } catch (Exception) { IsActive = false; } try { CPU = (double)new PerformanceCounter("Process", "% Processor Time", Name, true).NextValue() / Environment.ProcessorCount; } catch (Exception) { CPU = 0; } try { Memory = new PerformanceCounter("Process", "Working Set", Name, true).NextValue() * 0.0001; double computerMemory = new PerformanceCounter("Memory", "Available MBytes").NextValue(); MemoryPercent = Memory / computerMemory; } catch (Exception) { Memory = 0; } try { ThreadsCollection = process.Threads; Threads = process.Threads.Count; } catch (Exception) { } try { ModulesCollection = process.Modules; } catch (Exception) { } }
private static void ProcessesAndThreads() { Process[] processList = Process.GetProcesses("."); foreach (Process process in processList) { Console.WriteLine("A folyamat ({0}) szálai", process.ProcessName); ProcessThreadCollection ptc = process.Threads; foreach (ProcessThread thread in ptc) { Console.WriteLine("Id: {0}, Állapot: {1}", thread.Id, thread.ThreadState); } } }
public static void AddHooks() { foreach (var executable in executable_names) { Process[] processes = Process.GetProcessesByName(executable); foreach (var process in processes) { ProcessThreadCollection threads = process.Threads; foreach (ProcessThread thread in threads) { Console.WriteLine(thread.Id); } } } }
public void Refresh() { _process.Refresh(); Username = WindowsIdentity.GetCurrent().Name; FilePath = _process.MainModule?.FileName; Threads = _process.Threads; Id = _process.Id; Name = _process.ProcessName; StartTime = _process.StartTime; MemoryUsage = _process.WorkingSet64 / 1024.0 / 1024; IsActive = _process.Responding; ThreadCount = Threads.Count; Modules = _process.Modules; CpuUsage = CpuUsageCalc(); }
//Check if process is in suspended state public static bool CheckProcessSuspended(ProcessThreadCollection threadCollection) { try { //Debug.WriteLine("Checking suspend state for process: " + targetProcess.ProcessName + "/" + targetProcess.Id); ProcessThread processThread = threadCollection[0]; if (processThread.ThreadState == ThreadState.Wait && processThread.WaitReason == ThreadWaitReason.Suspended) { //Debug.WriteLine("The process main thread is currently suspended."); return(true); } } catch { } return(false); }
/// <summary> /// Increases or decreases the priority of a ProcessThread of the current process /// </summary> /// <param name="increase">Indicator to increase or decrease the priority level</param> /// <remarks>It is not advisable to call this method</remarks> private static void ChangeThreadPriority(bool increase) { ProcessThreadCollection threads = _currentProcess.Threads; int currentThreadId = GetCurrentWin32ThreadId(); ProcessThread thread; for (int i = 0; i < threads.Count; i++) { thread = threads[i]; if (thread.Id != currentThreadId) { thread.PriorityLevel = GetPriority(thread.PriorityLevel, increase); } } }
public static void UnfreezeThreads(Process proc) { ProcessThreadCollection threads = proc.Threads; foreach (ProcessThread thread in threads) { IntPtr threadHandle = OpenThread((int)ThreadAccessFlags.SUSPEND_RESUME, false, thread.Id); if ((int)threadHandle == 0) { return; } ResumeThread(threadHandle); CloseHandle(threadHandle); } }
private void Proc_Click(object sender, RoutedEventArgs e) { var sel = (Proc)Grid.SelectedItem; var proc = Process.GetProcessById(sel.ProcessId); ProcessThreadCollection sel1 = proc.Threads; string text = ""; int i = 0; foreach (ProcessThread thread in sel1) { i++; text += i + ". " + thread.Id.ToString() + " " + thread.StartTime.ToString() + " " + thread.PriorityLevel.ToString() + "\r\n" + "\r\n"; } Proc_Block.Text = text; }
private void Processes_SelectedIndexChanged(object sender, EventArgs e) { String longName = Processes.SelectedItem.ToString(); string name = longName.Substring(0, longName.IndexOf("-") - 1); string id = longName.Substring(longName.IndexOf("-") + 2); Process[] proc = Process.GetProcessesByName(name); MemoryNum.Text = (proc[0].PrivateMemorySize64 / (1024 * 1024)).ToString() + " MB"; notes.TryGetValue(id, out string o); Note.Text = o; CPUNum.Text = RunTest(name).ToString() + "%"; ProcessThreadCollection a = proc[0].Threads; ThreadsNum.Text = a.Count.ToString(); }
public void DisplayThreadStatistics() { ProcessThreadCollection threads = Process.GetCurrentProcess().Threads; _outWriter.WriteLine("ThreadCount: {0}", threads.Count); foreach (ProcessThread thread in threads) { _outWriter.WriteLine("\tThread: {0,8} | {1,10} | {2,8} | {3,8} | {4,8}", thread.Id, thread.StartTime.Ticks, thread.PrivilegedProcessorTime, thread.UserProcessorTime, thread.TotalProcessorTime); } }
public void TestThreadCollectionBehavior() { ProcessThread[] tArray = _process.Threads.Cast<ProcessThread>().ToArray(); int countOfTArray = tArray.Count(); // constructor ProcessThreadCollection threadCollection = new ProcessThreadCollection(tArray); // Count Assert.Equal(countOfTArray, threadCollection.Count); // get_item, Contains, IndexOf for (int i = 0; i < countOfTArray; i++) { Assert.Equal(tArray[i], threadCollection[i]); Assert.True(threadCollection.Contains(tArray[i])); Assert.Equal(i, threadCollection.IndexOf(tArray[i])); } // CopyTo ProcessThread[] threadArray = new ProcessThread[threadCollection.Count + 1]; threadCollection.CopyTo(threadArray, 1); for (int i = 0; i < countOfTArray; i++) { Assert.Equal(tArray[i], threadArray[i + 1]); } Assert.Throws<ArgumentOutOfRangeException>(() => threadCollection.CopyTo(threadArray, -1)); // Remove threadCollection.Remove(tArray[0]); Assert.Equal(-1, threadCollection.IndexOf(tArray[0])); Assert.False(threadCollection.Contains(tArray[0])); // Try remove non existent member threadCollection.Remove(tArray[0]); // Cleanup after remove threadCollection.Insert(0, tArray[0]); // Add threadCollection.Add(default(ProcessThread)); Assert.Equal(threadCollection.Count - 1, threadCollection.IndexOf(default(ProcessThread))); // Add same member again threadCollection.Add(default(ProcessThread)); Assert.Equal(threadCollection.Count - 2, threadCollection.IndexOf(default(ProcessThread))); Assert.Equal(default(ProcessThread), threadCollection[threadCollection.Count - 1]); // Cleanup after Add. threadCollection.Remove(default(ProcessThread)); threadCollection.Remove(default(ProcessThread)); Assert.False(threadCollection.Contains(default(ProcessThread))); // Insert int index = threadCollection.Count / 2; int initialCount = threadCollection.Count; threadCollection.Insert(index, null); Assert.Equal(index, threadCollection.IndexOf(null)); Assert.Equal(initialCount + 1, threadCollection.Count); // Insert at invalid index Assert.Throws<ArgumentOutOfRangeException>(() => threadCollection.Insert(-1, tArray[0])); // Explicit interface implementations Assert.False(((ICollection)threadCollection).IsSynchronized); Assert.NotNull(((ICollection)threadCollection).SyncRoot); threadArray = new ProcessThread[threadCollection.Count]; ((ICollection)threadCollection).CopyTo(threadArray, 0); Assert.Equal(threadCollection.Cast<ProcessThread>().ToArray(), threadArray); // GetEnumerator IEnumerator enumerator = threadCollection.GetEnumerator(); Assert.Throws<InvalidOperationException>(() => enumerator.Current); for (int i = 0; i < threadCollection.Count; i++) { enumerator.MoveNext(); Assert.Equal(threadCollection[i], enumerator.Current); } }