vb.net - NetworkChange.NetworkAvailabilityChanged, used in Outlook Add-In, does not fire when network cable is unplugged -
i have outlook add-in behavior i'd modify, depending on whether networked computer available. check availability, hoping check once when add-in loaded, wire handler system.net.networkinformation.networkchange.networkavailabilitychanged. have read event not distinguish between real network adapters , adapters virtual machines, , like. such, once event fired, plan ping computer in question, verify available.
that said, while debugging add-in, breakpoint indicates event not firing, when unplug network cable. pertinent code follows:
imports system.net.networkinformation imports microsoft.win32 public class thisaddin private sub thisaddin_startup() handles me.startup try 'do initial check see if online, store result drivesavailable = checkforexcelnetworkdrives() 'code associated other functionality 'wire event handlers addhandler networkchange.networkavailabilitychanged, new networkavailabilitychangedeventhandler(addressof localnetwork_statechanged) 'code associated other functionality catch ex exception end try end sub
then, inside module (static class), have event handler.
public sub localnetwork_statechanged(sender object, e networkavailabilityeventargs) 'when network state has changed, check see if can still access excel network drives dim newnetworkstate boolean = checkforexcelnetworkdrives() 'if drive connectivity has changed, throw new event, warn rest of system update behavior if newnetworkstate <> drivesavailable 'then call event raiseevent driveavailabilitychanged(nothing, new driveavailabilitychangedeventargs {.driveavailable = newnetworkstate}) end if 'update drivesavailable drivesavailable = newnetworkstate end sub
i haven't gotten debugging custom event yet, networkavailabilitychanged not appear firing. because i'm using in outlook add-in? other events wired in add-in's load event, , working. additionally, stepped through addhandler line, , appears execute without exception.
my next step set timer , ping network computer regularly. i'd rather not resort that, though.
i think may have answered own question. have multiple network adapters, included virtual machines. long any of them up, unplugging actual network did nothing. once disabled of other adapters, unplugging primary network connection caused networkavailabilitychanged fire.
Comments
Post a Comment