473,616 Members | 2,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PerformanceCoun ter array within Constructor

Here is my problem. I'm creating an Instrumentation class that will use
previously created Performance Categories and Counters in order to time
various processes (ie. query duration etc.). This Instrumentation class
will be used by a variety of "services", so the Categories and Counters
to be used within the object must be set during object construction.

So I created a class variable array of:

private static PerformanceCoun ter[] arrayCounters = null;

I created an overloaded constructor:

public Instrumentation (string logName, string PerfCategory, string[]
PerfCounters, string CASContext)

The parameters are passed in by the consuming service, with the
PerformanceCoun ters to be tracked in the form of a string array.

Within the constructor, I process the string array and try to set the
array members of PerformanceCoun ter array:

long arrayCountersIn dex = 0;
foreach (string counter in PerfCounters)
arrayCounters[arrayCountersIn dex++] = new
PerformanceCoun ter(PerfCategor y, counter, false);

The solution builds with no errors, but as soon as the previous code
line is executed during testing I get a "System.NullRef erenceException :
Object reference not set to an instance of an object." error on the
arrayCounters object.

The constructor will work if I comment out the setting of the array and
hard code the original class variable like this:

private static PerformanceCoun ter[] arrayCounters = {new
PerformanceCoun ter("ServiceNam e", "ServiceLocatio nDuration", false),
new PerformanceCoun ter("ServiceNam e", "OracleConnecti onDuration",
false),
new PerformanceCoun ter("ServiceNam e", "QueryDuration" , false),
new PerformanceCoun ter("ServiceNam e", "WebServiceDura tion", false)};

Any help I could get with getting that constructor array to work would
be greatly appreciated.

Thanks - jimbo
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
1 4215
Jimbo,

You have to declare the space for the array before you assign it.
Basically, in your constructor, before you look through the PerfCounters
array, you should do this:

// Allocate the array.
arrayCounters = new PerformanceCoun ter[PerfCounters.Le ngth];

And this will allocate your array. Of course, if PerfCounters is null,
you will get an error, so make that check beforehand. Other than that, the
code should work fine.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"jimbo" <no****@nospam. ca> wrote in message
news:u0******** ******@tk2msftn gp13.phx.gbl...
Here is my problem. I'm creating an Instrumentation class that will use
previously created Performance Categories and Counters in order to time
various processes (ie. query duration etc.). This Instrumentation class
will be used by a variety of "services", so the Categories and Counters
to be used within the object must be set during object construction.

So I created a class variable array of:

private static PerformanceCoun ter[] arrayCounters = null;

I created an overloaded constructor:

public Instrumentation (string logName, string PerfCategory, string[]
PerfCounters, string CASContext)

The parameters are passed in by the consuming service, with the
PerformanceCoun ters to be tracked in the form of a string array.

Within the constructor, I process the string array and try to set the
array members of PerformanceCoun ter array:

long arrayCountersIn dex = 0;
foreach (string counter in PerfCounters)
arrayCounters[arrayCountersIn dex++] = new
PerformanceCoun ter(PerfCategor y, counter, false);

The solution builds with no errors, but as soon as the previous code
line is executed during testing I get a "System.NullRef erenceException :
Object reference not set to an instance of an object." error on the
arrayCounters object.

The constructor will work if I comment out the setting of the array and
hard code the original class variable like this:

private static PerformanceCoun ter[] arrayCounters = {new
PerformanceCoun ter("ServiceNam e", "ServiceLocatio nDuration", false),
new PerformanceCoun ter("ServiceNam e", "OracleConnecti onDuration",
false),
new PerformanceCoun ter("ServiceNam e", "QueryDuration" , false),
new PerformanceCoun ter("ServiceNam e", "WebServiceDura tion", false)};

Any help I could get with getting that constructor array to work would
be greatly appreciated.

Thanks - jimbo
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3289
by: W1ld0ne74 | last post by:
I am implimenting Performance counters into a web application. I use the following code to create the counters during setup: private void SetupPerfCntrs() { System.Diagnostics.CounterCreationDataCollection CounterDatas = null; System.Diagnostics.CounterCreationData cdCounter4 = null; try { if(System.Diagnostics.PerformanceCounterCategory.Exists("LogisOnline"))
1
7271
by: Chris | last post by:
I'm trying to do something really easy: just get the % CPU load. However, I just get mostly 0's sprinkled with an occasional 100. I poked around on the web for info, but all the stuff I found (I think) does what I have below. Am I blanking out on something here? Getting the available RAM works fine. Code example below: using System;
4
1464
by: Eric A. Johnson | last post by:
For the following code: ' return String representation of CTriangleShape Public Overrides Function ToString() As String ' use MyBase reference to return CShape String Return MyBase.ToString & ";" & vbCrLf & _
3
2880
by: Rob Meade | last post by:
Hi all, I'm having a bit of trouble with the following function.... Private Function GetSystemUpTime() As TimeSpan ' declare variables Dim Result As TimeSpan Dim PerformanceCounter As PerformanceCounter
18
4199
by: toton | last post by:
Hi, In C++ when I initialize an array it, also initializes the class that it contains, which calls the default constructor. However, I want to initialize the array only (i.e reserve the space) and use my specific constructor to initialize the class. How to do it without using malloc? Something like Point* pt = new Point; I want it to reserve the space for N points only, and not to call default constructor. I dont have a default...
3
3383
by: John Salmon | last post by:
g++ complains about illegal access to a private member when the following is compiled with a private copy constructor for the class C. When the copy constructor is public, the program runs and demonstrates(?) that the copy constructor is never called (at least no sign of its chatter on std::cout is visible). So - is it necessary to have a public copy constructor in order to use "function style" initializers for an array of objects? ...
5
8238
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... I've got some custom performance counters that can have multiple instances. I use the PerformanceCounter() constructor with the instance name parameter. The thing that puzzles me, though, is that when I look in Perfmon for those counters, the instance name I've passed in has been lowercased. Why would that be? If you look at the Processes counter, it has mixed case instances. Thanks _Mark
14
2793
by: julie.siebel | last post by:
I've been wrestling with a really complex page. All the data is drawn down via SQL, the page is built via VBScript, and then controlled through javascript. It's a page for a travel company that shows all the properties, weeks available, pricing, etc. for a particular area of Europe. The data varies widely depending on the region; at times there will be 50 properties, and at other times only a half dozen. The cross referencing of...
11
5413
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post by:
Has anybody worked with performancecounter object to access counters on remote machine? I managed to write code that retrieves counters categories froma remote machine, when I try another remote machine I get "System.ComponentModel.Win32Exception" error. Error message is "The network path was not found." I have checked running services (RPC, Remote registery.....) on both machines and they are exactly the same. I am wondering if there is...
0
8203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8297
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7121
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6097
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4063
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4141
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2579
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.