을받은 보내누락 된 네트워크는 내가 여기에 대한 답을 다음과 AM /가
그가 말했듯이 모든 것을 구현했습니다. 내 모니터과 같이 초기화 :
netSentCounter.CategoryName = ".NET CLR Networking";
netSentCounter.CounterName = "Bytes Sent";
netSentCounter.InstanceName = Misc.GetInstanceName();
netSentCounter.ReadOnly = true;
내가 corrently 볼 수 Misc.GetInstanceName()
반환 "MyProcessName [ID]". 그러나 인스턴스가 지정된 범주에 존재하지 않는 예외를 점점 계속.
제 생각에는 실제로 보내거나받을 때까지 송수신 된 범주가 생성되지 않습니다.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<settings>
<performanceCounters enabled="true" />
</settings>
</system.net>
</configuration>
왜 여전히 에러가 발생합니까 :과 같이 대답에 설명 된대로
는 내가의 app.config를 추가 한?
public static class Monitoring
{
private static PerformanceCounter netSentCounter = new PerformanceCounter();
//Static constructor
static Monitoring()
{
netSentCounter.CategoryName = ".NET CLR Networking";
netSentCounter.CounterName = "Bytes Sent";
netSentCounter.InstanceName = Misc.GetInstanceName();
netSentCounter.ReadOnly = true;
}
/// <summary>
/// Returns the amount of data sent from the current application in MB
/// </summary>
/// <returns></returns>
public static float getNetSent()
{
return (float)netSentCounter.NextValue()/1048576; //Convert to from Bytes to MB
}
}
그리고 내 기타 클래스 :
public static class Misc
{
//Returns an instance name
internal static string GetInstanceName()
{
// Used Reflector to find the correct formatting:
string assemblyName = GetAssemblyName();
if ((assemblyName == null) || (assemblyName.Length == 0))
{
assemblyName = AppDomain.CurrentDomain.FriendlyName;
}
StringBuilder builder = new StringBuilder(assemblyName);
for (int i = 0; i < builder.Length; i++)
{
switch (builder[i])
{
case '/':
case '\\':
case '#':
builder[i] = '_';
break;
case '(':
builder[i] = '[';
break;
case ')':
builder[i] = ']';
break;
}
}
return string.Format(CultureInfo.CurrentCulture,
"{0}[{1}]",
builder.ToString(),
Process.GetCurrentProcess().Id);
}
/// <summary>
/// Returns an assembly name
/// </summary>
/// <returns></returns>
internal static string GetAssemblyName()
{
string str = null;
Assembly entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly != null)
{
AssemblyName name = entryAssembly.GetName();
if (name != null)
{
str = name.Name;
}
}
return str;
}
}
편집 :
여기 내 모니터링 코드 나는 문제가 무엇인지 확인 창에서 리소스 모니터를 열었습니다. 카운터는 app.config가 그렇게하도록 설정되어 있음에도 불구하고 시작되지 않습니다. 여기
내가 (내 응용 프로그램 전송 네트워크 활동 전후에이)를 참조그리고 이름이 내 방법을 반환하는 것이 아니다 것입니다. 내 메소드는 "SuperScraper [appId]"를 리턴하며 "Superscraper.vshost.exe"라고합니다.
그래서 지금은 두 가지 문제가 있습니다
- 내 카운터 앱 시작 년 - 이름에서 시작되지 않습니다 내가 당신의 예제를 시도 좋아
stacktrace를 표시 할 수 있습니까? 기타는 무엇입니까? [Here] (http://pastebin.com/f371375d6)는 모든 코드이며 붙여 넣기 만 복사하면됩니다. – Reniuz
기타는 내가 사용하는 라이브러리입니다. 나는 스택 추적을 게시 할 것이다. – TheGateKeeper
호출 스택이 거의 비어 있습니다. 모든 것은 내 라이브러리에서 메소드를 호출하는 것입니다. 코드가 라이브러리에 있고 내 응용 프로그램에 없기 때문에 문제입니까? 내 코드는 당신과 거의 같습니다. – TheGateKeeper