此代碼用於工作,現在它拋出異常並拒絕工作。代碼沒有改變。我懷疑原因是當我分區我的磁盤添加第二個分區。預期的目的是監視物理驅動器自身路徑處於打開狀態的百分比空閒時間。爲什麼此性能監視器代碼失敗
Try
Dim drive As String = BunzipInputStream.BinDirectory.Substring(0, 2)
Dim instname As String = Nothing
If drive.EndsWith(":"c, StringComparison.Ordinal) Then
Dim dix = New System.Diagnostics.PerformanceCounterCategory
dix.CategoryName = "PhysicalDisk"
For Each px In dix.GetInstanceNames()
If px.EndsWith(drive, StringComparison.OrdinalIgnoreCase) Then
instname = px
End If
Next
diskcounter = New System.Diagnostics.PerformanceCounter()
diskcounter.CategoryName = "PhysicalDisk"
diskcounter.CounterName = "% Idle Time"
diskcounter.InstanceName = instname
diskcounter.NextValue()
End If
Catch ex As Exception
'ENDS UP HERE AND ABORTS THE MONITOR
If Not diskcounter Is Nothing Then
diskcounter.Dispose()
diskcounter = Nothing
End If
End Try
(這是設置代碼。還有調用diskcounter.NextValue(),如果它不是顯示沒有一個定時器)。
System.InvalidOperationException occurred
Message=Counter is not single instance, an instance name needs to be specified.
Source=System
StackTrace:
at System.Diagnostics.PerformanceCounter.NextSample()
at System.Diagnostics.PerformanceCounter.NextValue()
at Redacted.PerformanceMon.OnHandleCreated(EventArgs e) in C:\development\redacted\redacted\Forms\PerformanceMon.vb:line XX
InnerException:
哪一個?我可以閱讀任何.NET系列。 – Joshua
@TomaszNurkiewicz它已經被標記爲.NET。雖然代碼是VB,但問題很可能不與VB特定的任何東西綁定。 –
什麼是拋出異常? –