C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » VB.NET Syntax »

Create Counter In vb.net


Posted Date: 12 Mar 2009    Resource Type: Code Snippets    Category: VB.NET Syntax
Author: DevashishMember Level: Gold    
Rating: 1 out of 5Points: 8



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

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
MyTxtBx.Clear()
End If
MyTxtBx.AppendText(vbNewLine & counter)

Me.Focus()
If counter > 5 Then counter = 0

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

End Sub




Responses

Author: harjit    01 Oct 2009Member 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.
CounterDatas.Add(cdCounter1)
CounterDatas.Add(cdCounter2)

'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




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
How to craete counter in vb.net  .  Create Counter in vb.net  .  Create counter  .  Counter in visual basic dot net  .  Counter in vb.net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: To excute insert,delete,update command in vb.net
Previous Resource: Simple HelloFriend Program
Return to Discussion Resource Index
Post New Resource
Category: VB.NET Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use