You better use an Eventwatcher to watch the 'MSNdis_MediaCo nnectStatus' ,
following gives you an idea how to proceed.
class Tester {
public static void Main() {
Tester we = new Tester();
ManagementScope scope = new ManagementScope ("root\\wmi" );
ManagementEvent Watcher w = null;
try {
WqlEventQuery q = new WqlEventQuery() ;
q.EventClassNam e = "__InstanceOper ationEvent";
q.WithinInterva l = new TimeSpan(0,0,3) ;
q.Condition = @"TargetInstanc e ISA 'MSNdis_MediaCo nnectStatus' ";
w = new ManagementEvent Watcher( q);
w.EventArrived += new EventArrivedEve ntHandler(we.Ne twEventArrived) ;
w.Start();
Console.ReadLin e(); // block main thread for test purposes
}
catch(Exception e) {
Console.WriteLi ne(e.Message);
}
finally {
w.Stop();
w.Dispose();
}
}
public void NetwEventArrive d(object sender, EventArrivedEve ntArgs e) {
//Get the Event object and show it
ManagementBaseO bject prop =
e.NewEvent.Prop erties["PreviousInstan ce"].Value as ManagementBaseO bject;
Console.WriteLi ne(Convert.ToBo olean(prop.Prop erties["NdisMediaConne ctStatus"].Value)?"Connec ted":"Disonnect ed");
}
}
Willy.
"Christophe r C" <Ch**********@d iscussions.micr osoft.com> wrote in message
news:FD******** *************** ***********@mic rosoft.com...
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
on my memory leak issue, but need to know if there is a better way then
WMI.
"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard. caspershouse.co m
"Christophe r C" <Ch**********@d iscussions.micr osoft.com> wrote in message
news:61******** *************** ***********@mic rosoft.com... > 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 [.NET/C# MVP]" wrote:
>
>> 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]
>> - mv*@spam.guard. caspershouse.co m
>>
>> "Christophe r C" <Ch**********@d iscussions.micr osoft.com> wrote in
>> message
>> news:39******** *************** ***********@mic rosoft.com...
>> >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.
>>
>>
>>