Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Help: How to use PerformanceCounter in WebForm Application?


Message #1 by "D" <yezh99@e...> on Thu, 31 Jan 2002 16:42:48

I have problem to use PerformanceCounter in ASPX Web Applications, the 

counter only give zero as result (the CPU performance actually is 40-50%, 

use another app to generate the CPU load). But the Performance Counter 

works fine at Windows Application (Can get the true CPU performance data). 

Does something wrong with my code? VS.NET version: Beta2 and Release



Web Application:

================================

Imports System.Diagnostics



Public Class WebForm1

    Inherits System.Web.UI.Page

    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    Protected WithEvents Label1 As System.Web.UI.WebControls.Label

    Public pc As PerformanceCounter = New PerformanceCounter

("Processor", "% Processor Time", "_Total", ".")



...





    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As 

System.EventArgs) Handles MyBase.Load

        'Put user code to initialize the page here

    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 

System.EventArgs) Handles Button1.Click

        Label1.Text = pc.NextValue.ToString

    End Sub

End Class

===============================



Windows (Label1 is Win Label)

===============================

Imports System.Diagnostics



Public Class Form1

    Inherits System.Windows.Forms.Form

    Public pc As PerformanceCounter = New PerformanceCounter

("Processor", "% Processor Time", "_Total", ".")



...



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 

System.EventArgs) Handles Button1.Click

        Label1.Text = pc.NextValue.ToString

    End Sub

End Class

================================





BTW, does anyone know how to set access right in the application to aceess 

another machine's performance counter? 





Thanks,

  Return to Index