Create Counter In

Private Sub MyTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTimer.Tick
Dim Status As Boolean = False
MyTimer.Interval = 1500
counter = counter + 1
If DatePart("n", TimeOfDay) Mod 10 = 0 And Status = False Then
Status = True

If DatePart("n", TimeOfDay) Mod 10 <> 0 Then
If Status = True Then
Status = False
End If
End If

End If

If MyTxtBx.Text.Length > 10 Then
End If
MyTxtBx.AppendText(vbNewLine & counter)

If counter > 5 Then counter = 0

MyTimer.Enabled = True
Catch ex As Exception
ErrorLog("Timer Function", Err.Description, Err.Source)
End Try

End Sub


Author: harjit01 Oct 2009 Member Level: Bronze   Points : 2

System.Diagnostics namespace provides classes which we can use to create and manipulate custom performance counters. Given below are the steps which we typically use for this purpose.

Create a collection of type CounterCreationDataCollection.
Create the counters you want to create as objects of type CounterCreationData and set their necessary properties.
Add the CounterCreationData objects to the collection by calling the collection's Add method.
Call the Create method on the PerformanceCounterCategory class and pass the collection to it.

'Assumes import statement for System.Diagnostics.dll
Dim CounterDatas As New System.Diagnostics.CounterCreationDataCollection()

'Create the counters and set their properties.
Dim cdCounter1 As New System.Diagnostics.CounterCreationData()
Dim cdCounter2 As New System.Diagnostics.CounterCreationData()

cdCounter1.CounterName = "Transactions Active"
cdCounter1.CounterHelp = "Indicates number of active transactions"
cdCounter1.CounterType = Diagnostics.PerformanceCounterType.NumberOfItems64
cdCounter2.CounterName = "Users Logged on"
cdCounter2.CounterHelp = "Gives the number of users logged on to the " _
& "application"
cdCounter2.CounterType = Diagnostics.PerformanceCounterType.NumberOfItems64

'Add both counters to the collection.

'Create the category and pass the collection to it.
PerformanceCounterCategory.Create("Accounting", _
"A set of counters for the accounting application", CounterDatas)

If you need to create a category with just one performance counter, you can use the overload of the Create method as follows:

PerformanceCounterCategory.Create("Accounting", _
"A set of counters for the accounting application", _
"Transactions Active","Gives number of transactions being processed")

There are a few things to consider regarding custom performance counters.

You cannot create custom categories and counters on remote machines.
Our interaction with custom counters and categories is restricted to read-only mode unless you explicitly specify otherwise. By default the counters created under server explorer are read only and under read-only mode you cannot update the value of the counter.
To create custom counters on the local computer you need administrative access.
You cannot create new counters within existing custom categories. If you need to add counters to categories that already exist, the only way you can do so is to delete the category and recreate it with all of its contents, including the new counters you want to add.
If you try to create a counter that already exists, an error would be thrown. You can check the existence of a counter before you create one. For example:

If Not (PerformanceCounterCategory.Exists("MyCat")) Then
PerformanceCounterCategory.Create("MyCat", "Desc", "MyCtr", "Desc")
End If

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: