当前位置: 首页>>代码示例>>C#>>正文


C# PerformanceCounter.NextValue方法代码示例

本文整理汇总了C#中System.Diagnostics.PerformanceCounter.NextValue方法的典型用法代码示例。如果您正苦于以下问题:C# PerformanceCounter.NextValue方法的具体用法?C# PerformanceCounter.NextValue怎么用?C# PerformanceCounter.NextValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.PerformanceCounter的用法示例。


在下文中一共展示了PerformanceCounter.NextValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCounterValue

        public static String GetCounterValue(PerformanceCounter pPerformanceCounter)
        {
            String retval = "";

            // Retrieve PerformanceCounter result based on its CounterType.
            switch (pPerformanceCounter.CounterType)
            {
                case PerformanceCounterType.NumberOfItems32:
                    retval = pPerformanceCounter.RawValue.ToString();
                    break;

                case PerformanceCounterType.NumberOfItems64:
                    retval = pPerformanceCounter.RawValue.ToString();
                    break;

                case PerformanceCounterType.RateOfCountsPerSecond32:
                    retval = pPerformanceCounter.NextValue().ToString();
                    break;

                case PerformanceCounterType.RateOfCountsPerSecond64:
                    retval = pPerformanceCounter.NextValue().ToString();
                    break;

                case PerformanceCounterType.AverageTimer32:
                    retval = pPerformanceCounter.NextValue().ToString();
                    break;

                default:
                    retval = null;
                    break;
            }

            return retval;
        }
开发者ID:tapman,项目名称:ipc-queue,代码行数:34,代码来源:UTCutil.cs

示例2: RAM_Count

 public int RAM_Count()
 {
     PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes");
     perfMemCount.NextValue();
     short currentAvailableMemory = (short)perfMemCount.NextValue();
     return currentAvailableMemory;
 }
开发者ID:MrPlayer141,项目名称:Jarvis,代码行数:7,代码来源:SyS_Counter.cs

示例3: CPUUsage

 private void CPUUsage()
 {
     Task.Factory.StartNew(() =>
     {
         PerformanceCounter cpuCounter = new PerformanceCounter();
         cpuCounter.CategoryName = "Processor";
         cpuCounter.CounterName = "% Processor Time";
         cpuCounter.InstanceName = "_Total";
         cpuCounter.NextValue();
         Thread.Sleep(20);
         cpu = cpuCounter.NextValue();
         while (true)
         {
             try
             {
                 Thread.Sleep(1000);
                 cpu = cpuCounter.NextValue();
             }
             catch (Exception e)
             {
                 ShowBalloon("CPU", e);
                 Thread.Sleep(10000);
             }
         }
     });
 }
开发者ID:hype-armor,项目名称:Fancy,代码行数:26,代码来源:MainWindow.xaml.cs

示例4: Scheduler

        /// <summary>
        /// This method is responsible for monitoring system resource and user activity with the computer
        /// And periodically changes the shared variable 'crawlerState'
        /// </summary>
        public void Scheduler()
        {
            PerformanceCounter pc = new PerformanceCounter("Processor", "% Idle Time", "_Total", true);

            LASTINPUTINFO info = new LASTINPUTINFO();
            info.cbSize = Marshal.SizeOf(typeof(LASTINPUTINFO));
            while (GlobalData.RunScheduler)
            {
                if (GetLastInputInfo(ref info))
                {
                    if ((Environment.TickCount - info.dwTime) / 1000 > 5 && (int)pc.NextValue() > 40)
                    {
                        crawlerState = CrawlerState.Run;
                    }
                    else
                    {
                        crawlerState = CrawlerState.Stop;
                        if ((Environment.TickCount - info.dwTime) / 1000 <= 5)
                            GlobalData.lIndexingStatus.Text = string.Format("Indexing is paused and will be resumed in {0} sec of computer inactivity [ CPU Idle : {1:F2}% ]", 5 - (Environment.TickCount - info.dwTime) / 1000, pc.NextValue());
                    }
                }
                Thread.Sleep(1000);
            }
            pc.Close();
        }
开发者ID:vineelkovvuri,项目名称:ExtendableDesktopSearch,代码行数:29,代码来源:FileSystemCrawler.cs

示例5: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     PerformanceCounter cpuCounter = new PerformanceCounter();
     PerformanceCounter ramCounter = new PerformanceCounter();
     cpuCounter.CategoryName = "Processor";
     cpuCounter.CounterName = "% Processor Time";
     cpuCounter.InstanceName = "_Total";
     ramCounter = new PerformanceCounter("Memory", "Available MBytes");
     System.Threading.Thread.Sleep(1000);
     cpuCounter.NextValue();
     System.Threading.Thread.Sleep(1000);
     Response.Write("Worker State: " + status + "<br>");
     Response.Write("CPU Utilization: " + cpuCounter.NextValue() + " <br>");
     Response.Write("RAM Utilization: " + ramCounter.NextValue() + " <br>");
     Response.Write("Urls Crawled: " + " <br>");
     Response.Write("Last 10 URLs crawled" + " <br>");
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
     CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
     CloudQueue urlQ = queueClient.GetQueueReference("pagequeue");
     urlQ.CreateIfNotExists();
     int? messageCount = urlQ.ApproximateMessageCount;
     Response.Write(messageCount.ToString());
     Debug.WriteLine("ApproximateMessageCount: " + urlQ.ApproximateMessageCount);
     Response.Write("Size of Queue: " + urlQ.ApproximateMessageCount + " <br>");
     Response.Write("Size of Index: " + " <br>");
     Response.Write("Errors and URLs: " + " <br>");
 }
开发者ID:hudpoi459,项目名称:Info344,代码行数:27,代码来源:Dashboard.aspx.cs

示例6: CPUMonitoring

        //Function will read and display current CPU usage
        public static async void CPUMonitoring(TextBox usageTextBox, TextBox warningTextBox)
        {

            PerformanceCounter cpuCounter = new PerformanceCounter();
            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName = "% Processor Time";
            cpuCounter.InstanceName = "_Total";

            while (true)
            {
                //First value always returns a 0
                var unused = cpuCounter.NextValue();
                await Task.Delay(1000);

                usageTextBox.Invoke(new Action(() =>
                {
                    CPUCounter = cpuCounter.NextValue();
                    usageTextBox.Text = CPUCounter.ToString("F2") + "%";
                }));
                CPUCalculations();
                CPUAnomalies.StartAnomalyDetection(warningTextBox);

                if (mainMenu.done)
                    break;
            }
        }
开发者ID:MikeHardman,项目名称:acIDS,代码行数:27,代码来源:CPUMonitor.cs

示例7: Request

        public byte[] Request(byte[] header)
        {
            string newheader = "HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n";

            string processmsg = Encoding.UTF8.GetString(header);

            if (processmsg.Contains(@"/status/all"))
            {
                PerformanceCounter cpuCounter = new PerformanceCounter("Processor Information", "% Processor Time");
                PerformanceCounter ramCounter;

                cpuCounter.CategoryName = "Processor";
                cpuCounter.CounterName = "% Processor Time";
                cpuCounter.InstanceName = "_Total";
                cpuCounter.NextValue();

                ramCounter = new PerformanceCounter("Memory", "Available MBytes");

                string jsoncpu = "{\"cpu\" : \"" + cpuCounter.NextValue() + "%\"}";
                string jsonmem = "{\"memory\" : \"" + ramCounter.NextValue() + "MB\"}";

                string json = "[" + jsonmem + "," + jsoncpu + "]";
                return System.Text.Encoding.UTF8.GetBytes(newheader + json);
            }

            return null;
        }
开发者ID:NickTullos,项目名称:NoDisk-WebServer,代码行数:27,代码来源:main.cs

示例8: CollectMetric

        public float CollectMetric(PluginResource pluginResource, string option = null)
        {
            // get a handle on the service first
            var service = ServiceController.GetServices().FirstOrDefault(s => s.DisplayName == option);
            if (service == null)
            {
                throw new Exception(string.Format("Windows service by name '{0}' not found", option));
            }

            if (service.Status == ServiceControllerStatus.Stopped)
            {
                return default(float);
            }
            else if (pluginResource.ResourceTextKey == StatusResource)
            {
                return 1;
            }

            // get a handle on the process
            var serviceMgtObj = new ManagementObject(@"Win32_Service.Name='" + service.ServiceName + "'");
            var serviceProcess = Process.GetProcessById(Convert.ToInt32(serviceMgtObj["ProcessId"]));

            // return perfomance counter value for process
            var perfCounter = new PerformanceCounter("Process", pluginResource.Label, serviceProcess.ProcessName);

            var value = perfCounter.NextValue();
            if (value == 0.0)
            {
                Thread.Sleep(1000);
                value = perfCounter.NextValue();
            }

            return value;
        }
开发者ID:marqui678,项目名称:finalchance.Panopta,代码行数:34,代码来源:ServicePlugin.cs

示例9: UpTime

 public TimeSpan UpTime()
 {
     using (var uptime = new PerformanceCounter("System", "System Up Time"))
         {
             uptime.NextValue();       //Call this an extra time before reading its value
             return TimeSpan.FromSeconds(uptime.NextValue());
         }
 }
开发者ID:jbayer,项目名称:windows-cf-demo,代码行数:8,代码来源:HomeController.cs

示例10: GetPerformanceCounterUptime

 // This sets the System uptime using the perf counters
 // this gives the best result but on a system with corrupt perf counters
 // it can freeze
 internal void GetPerformanceCounterUptime()
 {
     using (var uptime = new PerformanceCounter("System", "System Up Time"))
     {
         uptime.NextValue();
         Uptime = TimeSpan.FromSeconds(uptime.NextValue());
     }
 }
开发者ID:Chrisipte,项目名称:NewLib,代码行数:11,代码来源:Utils.cs

示例11: getSystemUpTime

 private static TimeSpan getSystemUpTime()
 {
     using (var upTime = new PerformanceCounter("System", "System Up Time"))
     {
         upTime.NextValue();
         return TimeSpan.FromSeconds(upTime.NextValue());
     }
 }
开发者ID:otamimi,项目名称:WpfFramework,代码行数:8,代码来源:ExceptionLogger.cs

示例12: cpu

 public string cpu()
 {
     var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
     cpuCounter.NextValue();
     Thread.Sleep(1000);
     var usage = cpuCounter.NextValue();
     return Convert.ToInt16(usage).ToString();
 }
开发者ID:bergdavi,项目名称:Performance-monitor,代码行数:8,代码来源:Form1.cs

示例13: th_cpu

        public static void th_cpu()
        {
            PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            float useless = cpuCounter.NextValue();
            System.Threading.Thread.Sleep(100);
            float cpuval = cpuCounter.NextValue();

            Console.Out.WriteLine(cpuval);
        }
开发者ID:LightningWright,项目名称:Visual-LiveStreamer,代码行数:9,代码来源:CPU.cs

示例14: getCoreUsage

 //Get the CPU usage for the core passed in
 public static int getCoreUsage(String core)
 {
     //Generate a new counter for core x
     PerformanceCounter coreUsage = new PerformanceCounter("Processor", "% Processor Time", core);
     coreUsage.NextValue();
     System.Threading.Thread.Sleep(750);
     int corePercentage = (int)coreUsage.NextValue();
     return corePercentage;
 }
开发者ID:JGMSoftware,项目名称:SysIntel,代码行数:10,代码来源:SystemInfo.cs

示例15: TotalCPUAsync

 async public Task<float> TotalCPUAsync()
 {
     PerformanceCounter cpuCounter = new PerformanceCounter();
     cpuCounter.CategoryName = "Processor";
     cpuCounter.CounterName = "% Processor Time";
     cpuCounter.InstanceName = "_Total";
     cpuCounter.NextValue();
     await Task.Delay(1000);
     return cpuCounter.NextValue();
 }
开发者ID:vanhouc,项目名称:SystemCheckerPlus,代码行数:10,代码来源:ProcessService.cs


注:本文中的System.Diagnostics.PerformanceCounter.NextValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。