Determining if a device is connected or disconnected issue

I’m trying to set up my program so that if a device is not connected at startup or disconnected the program will still be active and if that device is connected it will start to be used.

I need to do this in a couple of ways.

  1. On my I2C bus I have a device that I want to be able to do this with.
  2. Directly connected to a digital out pin.

More or less similar to a plug and play system.

Please note that I am using the Netduino Plus.