Getting Information about the ASP.NET Worker Process






Getting Information about the ASP.NET Worker Process

One of the most important processes running on a Web server is the ASP.NET worker process. The ASP.NET worker process handles requests for the execution of the ASP.NET pages. In this section, you'll learn how to retrieve specific execution information for the ASP.NET worker process using the classes of the System.Web namespace.

The ProcessModelInfo class of the System.Web namespace contains two methods that return information about the ASP.NET worker processes. Figure discusses these methods.

Figure Static Methods of the ProcessModelInfo Class

Method

Description

GetCurrentProcessInfo()

Returns a ProcessInfo object that contains information about the ASP.NET worker process executing the current request

GetHistory()

Returns an array of ProcessInfo objects that contain information for the most recent (maximum being 100) ASP.NET worker processes

Both methods listed in Figure return ProcessInfo objects. The ProcessInfo class provides information for the corresponding ASP.NET worker process. Figure lists the properties of the ProcessInfo class.

Figure Properties of the ProcessInfo Class

Property

Description

Age

Gets the length of time the worker process has been running

PeakMemoryUsed

Gets the maximum amount of memory the process has used

ProcessID

Gets the process ID assigned to the process

RequestCount

Gets the number of start requests for the process

ShutdownReason

Specifies a reason why the process was shut down

StartTime

Gets the time at which the process started

Status

Gets the status of the process

Take the following steps to see the ProcessModelInfo and the ProcessInfo classes in action:

  1. Open Visual Studio .NET and create a new blank solution named 315C15 at c:\inetpub\wwwroot\ExamCram. (You might need to change the directory based on your configuration.)

  2. Add a new Visual C# ASP.NET Web Application at the following location: http://localhost/ExamCram/315C15/Example15_1.

  3. Drag a Label control, a DataGrid control (dgProcessHistory), and a Button control (btnRefresh) onto the Web form.

  4. Invoke the Properties window and set the AutoGenerateColumns property of the DataGrid control to false. Select the Columns property and click the ellipse (…) button.

  5. This opens the DataGrid Properties dialog box. Select the Bound Column from the Available columns list box and click the > button. This adds a bound column in the Selected Columns list box. Enter ProcessID in the Header Text and Data Field text boxes, and click the Apply button. Add a few more bound columns with Header Text and Data Field properties set to StartTime, Age, RequestCount, PeakMemoryUsed, Status, and ShutdownReason.

  6. Switch to Code view and add the following using directive:

    using System.Diagnostics;
    
  7. Add the following code to the Page_Load() event handler:

    private void Page_Load(object sender, System.EventArgs e)
    {
        // Setting the DataGrid's DataSource to the
        // array of the ProcessInfo objects returned
        dgProcessHistory.DataSource = ProcessModelInfo.GetHistory(100);
        dgProcessHistory.DataBind();
    }
    
  8. Run the project. You should see the details about the recent ASP.NET worker processes as shown in Figure.

    Figure. The ProcessModelInfo and ProcessInfo classes provide information about the recent ASP.NET worker processes.

    graphics/15fig01.jpg

Figure shows a list of recent ASP.NET worker processes that started on the Web server since the last IIS reset. Only one of the worker processes is active; the other has been shut down. ASP.NET has a built-in mechanism to detect memory leaks, process crashes, and deadlocks. ASP.NET automatically tracks the problem and recycles the worker process if necessary.

You can configure the parameters ASP.NET uses to recycle the worker process. These settings can be configured in the <processModel> element of the machine.config file.


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows