Here is some info from another thread where they are running code based on connected/disconnected status. Does this help?