I need help on the best why to query network status

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am currently working on an app the will be a shell replacement. Part of the
goal is to list the current network status; basically I need to know if the
network card is plugged in. I am currently using WMI to query all adapters to
see if they have a connected status. The status is updated every 30minutes. I
noticed this is leaking memory. I am looking for suggestions. I am running
this on an asynchronous thread call with callbacks to a delegate.
 
Why do you think this is leaking memory? Because you see the number in
the task manager go up? If this is the case, that is the normal behavior
for .NET, and it is not leaking memory.
 
After an hour the program goes from using 18 megs to 59 megs. After 8 hours
it states the progrmaing is using 100 megs and the sytem is so slow it is
unusable.

Nicholas Paldino said:
Why do you think this is leaking memory? Because you see the number in
the task manager go up? If this is the case, that is the normal behavior
for .NET, and it is not leaking memory.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
I am currently working on an app the will be a shell replacement. Part of
the
goal is to list the current network status; basically I need to know if
the
network card is plugged in. I am currently using WMI to query all adapters
to
see if they have a connected status. The status is updated every
30minutes. I
noticed this is leaking memory. I am looking for suggestions. I am running
this on an asynchronous thread call with callbacks to a delegate.
 
But you still haven't answered the question. Are you looking at Task
Manager, or is there a performance counter that is indicating that you have
a memory leak.

If it is in fact a memory leak, there is a good chance that you are not
disposing of something properly. Are you sure that you are calling Dispose
on anything that implements IDisposable at the appropriate time? You might
think you are, but if there truly is a memory leak, this would be the most
obvious culprit.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
After an hour the program goes from using 18 megs to 59 megs. After 8
hours
it states the progrmaing is using 100 megs and the sytem is so slow it is
unusable.

Nicholas Paldino said:
Why do you think this is leaking memory? Because you see the number
in
the task manager go up? If this is the case, that is the normal behavior
for .NET, and it is not leaking memory.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
I am currently working on an app the will be a shell replacement. Part
of
the
goal is to list the current network status; basically I need to know if
the
network card is plugged in. I am currently using WMI to query all
adapters
to
see if they have a connected status. The status is updated every
30minutes. I
noticed this is leaking memory. I am looking for suggestions. I am
running
this on an asynchronous thread call with callbacks to a delegate.
 
I know I am the one creating the leak. What I am really looking for is a
better way to detect if the network cord is unplugged. Basically I need an
event to notify when there are changes to connectivity status. I am working
But you still haven't answered the question. Are you looking at Task
Manager, or is there a performance counter that is indicating that you have
a memory leak.

If it is in fact a memory leak, there is a good chance that you are not
disposing of something properly. Are you sure that you are calling Dispose
on anything that implements IDisposable at the appropriate time? You might
think you are, but if there truly is a memory leak, this would be the most
obvious culprit.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
After an hour the program goes from using 18 megs to 59 megs. After 8
hours
it states the progrmaing is using 100 megs and the sytem is so slow it is
unusable.

Nicholas Paldino said:
Why do you think this is leaking memory? Because you see the number
in
the task manager go up? If this is the case, that is the normal behavior
for .NET, and it is not leaking memory.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am currently working on an app the will be a shell replacement. Part
of
the
goal is to list the current network status; basically I need to know if
the
network card is plugged in. I am currently using WMI to query all
adapters
to
see if they have a connected status. The status is updated every
30minutes. I
noticed this is leaking memory. I am looking for suggestions. I am
running
this on an asynchronous thread call with callbacks to a delegate.
 
You better use an Eventwatcher to watch the 'MSNdis_MediaConnectStatus' ,
following gives you an idea how to proceed.

class Tester {
public static void Main() {
Tester we = new Tester();
ManagementScope scope = new ManagementScope("root\\wmi");
ManagementEventWatcher w = null;
try {
WqlEventQuery q = new WqlEventQuery();
q.EventClassName = "__InstanceOperationEvent";
q.WithinInterval = new TimeSpan(0,0,3);
q.Condition = @"TargetInstance ISA 'MSNdis_MediaConnectStatus' ";
w = new ManagementEventWatcher( q);
w.EventArrived += new EventArrivedEventHandler(we.NetwEventArrived);
w.Start();
Console.ReadLine(); // block main thread for test purposes
}
catch(Exception e) {
Console.WriteLine(e.Message);
}
finally {
w.Stop();
w.Dispose();
}
}
public void NetwEventArrived(object sender, EventArrivedEventArgs e) {
//Get the Event object and show it
ManagementBaseObject prop =
e.NewEvent.Properties["PreviousInstance"].Value as ManagementBaseObject;
Console.WriteLine(Convert.ToBoolean(prop.Properties["NdisMediaConnectStatus"].Value)?"Connected":"Disonnected");
}

}

Willy.

Christopher C said:
I know I am the one creating the leak. What I am really looking for is a
better way to detect if the network cord is unplugged. Basically I need an
event to notify when there are changes to connectivity status. I am
working
But you still haven't answered the question. Are you looking at Task
Manager, or is there a performance counter that is indicating that you
have
a memory leak.

If it is in fact a memory leak, there is a good chance that you are
not
disposing of something properly. Are you sure that you are calling
Dispose
on anything that implements IDisposable at the appropriate time? You
might
think you are, but if there truly is a memory leak, this would be the
most
obvious culprit.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
After an hour the program goes from using 18 megs to 59 megs. After 8
hours
it states the progrmaing is using 100 megs and the sytem is so slow it
is
unusable.

:

Why do you think this is leaking memory? Because you see the
number
in
the task manager go up? If this is the case, that is the normal
behavior
for .NET, and it is not leaking memory.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I am currently working on an app the will be a shell replacement.
Part
of
the
goal is to list the current network status; basically I need to know
if
the
network card is plugged in. I am currently using WMI to query all
adapters
to
see if they have a connected status. The status is updated every
30minutes. I
noticed this is leaking memory. I am looking for suggestions. I am
running
this on an asynchronous thread call with callbacks to a delegate.
 
Back
Top