这里是我的代码性能计数器输入字符串的不正确的格式C#
float cpuLoad = 0;
try{
MessageBox.Show("Running");
//CPU Load
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
MessageBox.Show("Performance Counter Created");
cpuLoad = cpuCounter.NextValue();
System.Threading.Thread.Sleep(1000);
cpuLoad = cpuCounter.NextValue();
MessageBox.Show("Clock Speed Gathered");
//Remaining Code
}
catch(Exception ex) { MessageBox.Show(ex.Message); }
我周围有一个尝试,渔获物和这里它抛出Input string was not in a correct format
例外。
它获得通过打印头两个消息框,然后抛出异常。
现在,这里是我不能左右我的头,它在Windows 7旗舰版和Windows Server 2003,但我的同事Windows 7旗舰版失败。它用于在他的电脑上工作,但突然停止。近代史上唯一的区别是他改变了他的网络。
编辑
框架4今早更新。但我有我的机器上一样,所以如果这是它为什么不能在我的
出现的框架问题的任何想法引起IM失去
测试他的机器
其在没有上第一cpuLoad = cpuCounter.NextValue()
堆栈跟踪
System.FormatException was unhandled
Message="Input string was not in a correct format."
Source="mscorlib"
StackTrace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Diagnostics.PerformanceCounterLib.GetStringTable(Boolean isHelp)
at System.Diagnostics.PerformanceCounterLib.get_NameTable()
at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
at System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists)
at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
at System.Diagnostics.PerformanceCounter.Initialize()
at System.Diagnostics.PerformanceCounter.NextSample()
at System.Diagnostics.PerformanceCounter.NextValue()
at CounterTest.Form1..ctor() in C:\Users\x\Documents\x\Applications & Software Development\C# Projects\CounterTest\CounterTest\Form1.cs:line 35
at CounterTest.Program.Main() in C:\Users\x\Documents\x\Applications & Software Development\C# Projects\CounterTest\CounterTest\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
哦应用程序正在调试模式下进行编译,如果有什么差别 – 2010-06-25 21:53:19
您可以张贴堆栈跟踪吗? – 2010-06-25 21:53:52
那么,究竟是什么样的调用抛出异常呢? – 2010-06-25 21:55:49