[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

System.Diagnostics.Stopwatch.Frequency Help

Posted on 2006-05-08
8
Medium Priority
?
440 Views
Last Modified: 2009-07-29
Anyone here have an example of System.Diagnostics.Stopwatch ?

I can't get the stopwatch.frequency property to work.

Anytime I try to use it I get an error:
"access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated."

'Global
Private swStopWatch As New Stopwatch

Private Sub _SendTCPPacket(ByVal ar As IAsyncResult)
     swStopWatch.Start()
     'code
End Sub

Private Sub _ReceiveTCPPacket(ByVal ar As IAsyncResult)
                swStopWatch.Stop()
                UpdateHistory(" Millseconds:" & swStopWatch.Elapsed.TotalMilliseconds) 'THIS WORKS
                UpdateHistory(swStopWatch.Frequency.MinValue) 'THIS DOES NOT
                UpdateHistory(swStopWatch.Frequency.MaxValue) 'THIS DOES NOT
End Sub
0
Comment
Question by:Hepen
  • 5
  • 3
8 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16636911
               UpdateHistory(Stopwatch.Frequency.MinValue) 'THIS DOES NOT
                UpdateHistory(Stopwatch.Frequency.MaxValue) 'THIS DOES NOT

Frequency is shared property and should be accessed using class name and not instance.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16636919
Example of using this class can be found in the MSDN topic Stopwatch Class:
http://msdn2.microsoft.com/en-us/library/ebf7z0sw.aspx
0
 

Author Comment

by:Hepen
ID: 16636948
that example doesn't show how to use frequency unfortunately.

Do you know how by any chance?

You say it is a shared property and should be accessed using class name and not instance.

How do you do that?
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 16636966
              UpdateHistory(Stopwatch.Frequency.MinValue)
               UpdateHistory(Stopwatch.Frequency.MaxValue)

Use Stopwatch instead of swStopWatch.
0
 

Author Comment

by:Hepen
ID: 16636987
Isn't frequency supposed to return an average or something?
0
 

Author Comment

by:Hepen
ID: 16637007
OMG i thought frequency was a convenient way of returning an average of all the start,stop measurements. LOL
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16637129
Stopwatch.Frequency returns timer frequency. This is processor feature, therefore it is shared and accessed using class name. This parameter is used in program written using Windows API to count time interval, knowing number of ticks and timer frequency. StopWatch class has ElapsedMilliseconds value, so Frequency is not required for calculating time interval. You can use it to estimate presision. You can also use IsHighResolution property for this.
However, I don't beleive that there are computers running .NET without high resolution timer.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16637138
This is MSDN example:

Public Shared Sub DisplayTimerProperties()

   ' Display the timer frequency and resolution.
   If Stopwatch.IsHighResolution Then
      Console.WriteLine("Operations timed using the system's high-resolution performance counter.")
   Else
      Console.WriteLine("Operations timed using the DateTime class.")
   End If
   
   Dim frequency As Long = Stopwatch.Frequency
   Console.WriteLine("  Timer frequency in ticks per second = {0}", frequency)
   Dim nanosecPerTick As Long = 1000000000 / frequency
   Console.WriteLine("  Timer is accurate within {0} nanoseconds", nanosecPerTick)

End Sub
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question