Voici mon codecompteur de performance chaîne d'entrée n'a pas été dans un bon format 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); }
J'ai essayer et attraper autour d'elle et voici l'exception qu'il jette Input string was not in a correct format
.
Il passe à travers l'impression des deux premières boîtes de message, puis lève l'exception.
Maintenant, voici ce que je ne peux pas obtenir ma tête autour, il fonctionne sur Windows 7 Ultimate et Windows Server 2003, mais sur mes collègues Windows 7 Ultimate il échoue. Il a l'habitude de travailler sur son ordinateur, mais tout à coup, il s'arrête. La seule différence dans la proche histoire a été qu'il a changé son réseau.
Modifier
cadre 4 a été mis à jour ce matin. Mais je l'ai sur ma machine, donc si elle était la question du cadre pourquoi il ne se produit pas sur le mien
Toutes les idées provoquent im perdu
Testée sur sa machine
Son échec à le premier cpuLoad = cpuCounter.NextValue()
Stack Trace
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:
Oh l'application est en cours de compilation en mode débogage si cela fait une différence –
Pourriez-vous poster la trace de la pile s'il vous plaît? –
Alors, quel appel lève exactement l'exception? –