How to determine the number of window handles an application uses?

What is the best way to determine how many windows an application processes? Is there a WMI performance tool or counter that I could use?

I would like to run the application and look at some counter and see how the number of window handles increases.

for (int i=0; i < 1000; i++) { System.Threading.Thread.Sleep(1000); RichTextBox rt = new RichTextBox(); rt.Text = "hi"; this.Controls.Add(rt); } 

I run the code above and look at the handle counter in the process, and it does not seem to increase. Is there something I was looking for wrong?

+4
source share
4 answers

Perfmon that comes with your computer can do this. You can also add a column to the process tab of the task manager (Handle Count).

Instructions for Perfmon

  • Add a counter (click +)
  • Select "Process" under "Performance Object"
  • Select the pen counter in the counter list
  • Select your process from the list of instances.
  • Click "Add", click "Close"

To get a graph in a range, you must right-click on it in the list, select the properties, and then select the correct scale (.1 or .01 will probably be correct)

Edit (in response to the information added): I think you simply proved that creating RichTextBoxes does not result in the assignment of Handles. I don’t think this is really necessary until you edit the control, and it can be smart enough to do this, since allocating too many resources for the control that is inactive will make it difficult to have too many controls on (think about Excel, for example).

+9
source

Process Monitor is very convenient in interactive monitoring of all types of resources used by Windows processes.

Process Monitor is an advanced monitoring tool for Windows that shows the real-time file system, registry activity, and processes / threads.

Note. If you want to find information programmatically, .Net provides access to all performance counters. You are using the System.Diagnostics.PerformanceCounter class as follows:

 PerformanceCounter PC=new PerformanceCounter(); PC.CategoryName="Process"; PC.CounterName="Handles"; PC.InstanceName="MyProc"; MessageBox.Show(PC.NextValue().ToString()); 
+3
source

The number of handlers shown by the task manager is the same as shown by PerfMon

The ProcessExplorer tool from sysinternals can display various types of descriptors + their names that the process uses, and you can get a good idea by looking at this list about the composition of your program handles.

But I'm afraid that this does not summarize these number of type types for you.

To view the actual descriptors and their types using ProcessExplorer - View - show the bottom view of the panel - handles.

You can also use the spy window tool of the sort window, which displays all the windows in the system, such as Microsoft spy ++ or Managed Spy ++ ( http://msdn.microsoft.com/en-us/magazine/cc163617.aspx )

This will let you see if your windows will be created.

0
source

Perfmon or the task manager cannot provide you with the number of WINDOW handlers used by the process, only the total number of descriptors of all types (file, stream, etc.).

The best information I can find on this subject is this post, which indicates that the number of window handlers for a process can be determined by listing all the child windows of the main process window.

0
source

Source: https://habr.com/ru/post/1277697/


All Articles