Process Explorer and Process Monitor can help you understand a program

Process Explorer and Process Monitor are must-have free utilities that you can download from https://technet.microsoft.com/en-us/sysinternals/bb795533.aspx

 

For example you can use ProcExp to examine a particular behavior of Visual Studio.

 

Start Visual Studio (any version). I was using VS 2008.

Start Process Explorer (as Administrator)

Click on the Devenv.exe process (the main VS process) to select it.

Choose View->Show Lower Pane and View->Lower Pane View->Handles

In VS, try creating a new VB or C# console application.

 

Now ProcExp shows a list of handles opened by this particular process. A handle can be a file, an Event, a process, a thread, a registry key, etc.

 

Did you ever get a permission denied error message because the file is “opened by another process” but you didn’t know which process?

 

If you click on the Name column, the list of handles will be sorted by name.

 

I chose File->Save As to save the whole shebang to a file. Here’s a portion, showing the handle type (File), the file name, and the handle value:

 

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\enterprisesec.config.cch 0x264

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\security.config.cch 0x260

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\Microsoft.VisualBasic.xml 0x14D0

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\mscorlib.xml 0x8C0

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\System.Data.xml 0x89C

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\System.xml 0x13F4

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.CSharp.targets 0x7F4

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.VisualBasic.dll 0x88C

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.VisualBasic.targets 0x7F8

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.WinFX.targets 0x7E8

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll 0x86C

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll 0x13D4

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll 0x924

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll 0x174C

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll 0x15B8

File C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets 0x804

File C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.VisualBasic.targets 0x808

File C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CSharp.targets 0x7EC

File C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.VisualBasic.targets 0x7F0

File C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.WinFx.targets 0x80C

File C:\Windows\Microsoft.NET\Framework\v3.5\SqlServer.targets 0x7FC

 

You can see this portion by scrolling the view to some framework assemblies.

 

Now play around with Visual Studio to see what files in this folder get opened and closed. The newly opened ones show in green for a couple seconds, while ones that close flash red, then disappear.

 

In particular, try creating a new VB Console application to see which assemblies get loaded. Close the solution, reopen it a few times. You’ll see these files get opened/closed:

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll 0x13D4

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll 0x924

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll 0x174C

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll 0x15B8

 

Now type the letter “C” within Sub Main and you’ll see these XML files get opened:

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\Microsoft.VisualBasic.xml 0x14D0

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\mscorlib.xml 0x8C0

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\System.Data.xml 0x89C

File C:\Windows\Microsoft.NET\Framework\v2.0.50727\en\System.xml 0x13F4

They will remain opened until you close the solution.

 

Now try typing the letter “C” before the Sub Main, but after the Module Module1 line.

No files get opened! Why?

 

Why does where you type make a difference? What are these files used for?

 

Here’s an excerpt. Does it provide any clues?

 

    <member name="T:System.Uri">

      <summary>Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.</summary>

      <filterpriority>1</filterpriority>

    </member>

    <member name="M:System.Uri.#ctor(System.String)">

      <summary>Initializes a new instance of the <see cref="T:System.Uri" /> class with the specified URI.</summary>

      <param name="uriString">A URI. </param>

      <exception cref="T:System.ArgumentNullException">

        <paramref name="uriString" /> is null. </exception>

      <exception cref="T:System.UriFormatException">

        <paramref name="uriString" /> is empty.-or- The scheme specified in <paramref name="uriString" /> is not correctly formed. See <see cref="M:System.Uri.CheckSchemeName(System.String)" />.-or- <paramref name="uriString" /> contains too many slashes.-or- The password specified in <paramref name="uriString" /> is not valid.-or- The host name specified in <paramref name="uriString" /> is not valid.-or- The file name specified in <paramref name="uriString" /> is not valid. -or- The user name specified in <paramref name="uriString" /> is not valid.-or- The host or authority name specified in <paramref name="uriString" /> cannot be terminated by backslashes.-or- The port number specified in <paramref name="uriString" /> is not valid or cannot be parsed.-or- The length of <paramref name="uriString" /> exceeds 65534 characters.-or- The length of the scheme specified in <paramref name="uriString" /> exceeds 1023 characters.-or- There is an invalid character sequence in <paramref name="uriString" />.-or- The MS-DOS path specified in <paramref name="uriString" /> must start with c:\\.</exception>

    </member>

 

 

Now try typing this very slowly and watch the Proc Exp Handles list:

                Dim x = New Uri(

 

(In C#, try “Uri” )

 

You’ll get Intellisense and the parameter help for the constructor of the Uri. The strings for that help come from this XML file.

 

The “filterPriority” element indicates whether the item shows up on the Common or the All tab of the Intellisense list (VB only).

(BTW, did you know you can switch between the common and the All tabs Alt-Comma and Alt-Period?)

 

If you like, you can customize the XML of the framework assemblies. Edit the text and save it.

 

You can even author your own:

Try this: before Sub Main type 3 apostrophes. (for C#, try 3 slashes) This will appear:

    ''' <summary>

    '''

    ''' </summary>

    ''' <remarks></remarks>

 

Try hitting Enter then “<” after the </summary> tag. Intellisense will prompt you for other XML Doc fields, such as Example, Remarks, See Also, Param.

 

You can fill out the “XmlDoc” information. On Project->Properties->Compile there’s a checkbox “Generate XML Documentation file” (see How to: Generate XML Documentation for a Project )

 

Now when your assemblies get referenced, you can provide the strings for intellisense, parameter help, info tips to show!

 

The “en” in the file path name indicates “English” version of the docs. Other languages will work too, if you have them installed on your machine.

 

The letter “C” in the VB sample above triggers intellisense. If you’re not within a method, then only a few keywords are allowed that start with “C”, like Class, Const, or Custom. Thus the XML doc files aren’t necessary.

 

If you’re within the context of a method, you can potentially type the name of a shared method, for example: Console.WriteLine, so the XML files are loaded.

 

Try experimenting with other project types, such as C#, a Web app, or even start Visual FoxPro to see what files get opened under varying conditions. Try adding references to other assemblies.

 

We’ll explore more of ProcExp and ProcMon in future posts.