Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 282193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:16:05+00:00 2026-05-12T05:16:05+00:00

Probably a rookie error, but i’m getting something strange. i’m trying to weave a

  • 0

Probably a rookie error, but i’m getting something strange. i’m trying to weave a .NET performance counter into an application.

When i call the incrementBy(value) method on my avg performance counter it is changing the RawValue of my base counter by value as well. i checked the variable names and think everything is correct.

Then when i call increment() on my base counter it adds 1 to the rawvalue of the avgcounter as well as incrementing the base counter… adding insult to injury!

Has anyone else seen this kind of behavior? Any suggestions for what’s going on and how to fix it?

In code i’m using two different counters to measure the time a merge sort i wrote takes. i have a instantaneous counter for the elapsed time of the sort and an average counter.

Dim timePiece As New Stopwatch()

timePiece.Start()
MergeSort()
timePiece.Stop()

ElapsedCounter.RawValue = timePiece.ElapsedMilliseconds
AvgCounter.IncrementBy(timePiece.ElapsedMilliseconds)
AvgCounterBase.Increment()

What i’m seeing occur is:

'Elapsed counter works as expected  
'AvgCounter RawValue is 7, AvgCounterBase RawValue is also 7 before incrementing
 AvgCounter.IncrementBy(value) 'AvgCounter.RV is 7+value, AvgCounterBase is 7+value   
 AvgCounterBase.Increment()    'AvgCounter.RV is 7+value+1, AvgCounterBase is 7+value+1  

i think i may be using the counters wrong, but why does changing the rawvalue of the average seem to also change the rawvalue of the base? i dont think that’s supposed to happen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:16:05+00:00Added an answer on May 12, 2026 at 5:16 am

    That behavior is how it should work. Increment and IncrementBy are essentially thread-safe versions of what you could do yourself by modifying RawValue directly. When the counter is only accessed by a single thread these statements:

    counterVariable.RawValue++;
    counterVariable.RawValue += 2;
    

    are equivalent to these statements:

    counterVariable.Increment();
    counterVariable.IncrementBy(2);
    

    If accessed by multiple threads, modifying RawValue directly is not thread-safe and can possibly lose some of the updates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a rookie question but; Let's say I have an ActionResult that
This is probably a rookie question, but I need to know what I need
Probably a long question for a simple solution, but here goes... I have a
I probably spend far too much time trying to make my visual interfaces look
This probably has a simple answer, but I must not have had enough coffee
This probably sounds really stupid but I have noo idea how to implement jquery's
Probably really a rookie question here about xcode (for the iphone).. When I issue
I am trying to add a JButton Array to my GridLayout but it seems
Probably down to preference but I was just after some of your thoughts; I
Probably a stupid question but I have a lot of: if(X) { foreach(var Y

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.