Detecting the Kinect sensor state change/disconnection example

Sign in to queue


Today's project is a simple example, but one that will help you add that professional and completeness to your Kinect for Windows SDK applications...

[# KINECTSDK] HowTo: Detect the sensor state change and sensor disconnection

If we go ahead we can see in KinectSensor we have a special event to capture the States of sensors: StatusChanged.This event also can be used to detect when you connect or disconnect a sensor to the USB port.

An example with this code in a console application:


When we launched the application we can see how the timestamp, shows a small difference between the connected sensor and active sensor (lines 2y3 vs 4.5 lines)

   1: 20:23:32.9637224 - Start sample application
   2: 20:23:40.0351074 - New Status: Initializing
   3: 20:23:40.0351074 - Sensor Status: Initializing
   4: 20:23:44.7783652 - New Status: Connected
   5: 20:23:44.7783652 - Sensor Status: Connected
   6: 20:23:51.2279666 - New Status: Disconnected
   7: 20:23:51.2279666 - Sensor Status: Disconnected
   8: 20:23:59.2548372 - New Status: Initializing
   9: 20:23:59.2558370 - Sensor Status: Initializing
  10: 20:24:03.5861851 - New Status: Connected
  11: 20:24:03.5861851 - Sensor Status: Connected
  12: 20:24:08.8158976 - New Status: Disconnected
  13: 20:24:08.8158976 - Sensor Status: Disconnected

If we also want to take advantage of this event to initialize the sensor, we must bear in mind that we can only do so when the State of the sensor is "connected".

The complete example below shows one way of doing it.

Project Information URL:

using System; 
using Microsoft.Kinect;

namespace KinectStatus01 
    class Program 
        private static KinectSensor _kinect; 
        static void Main(string[] args) 
             Console.WriteLine("{0} - Start sample application", DateTime.Now.TimeOfDay.ToString()); 
             KinectSensor.KinectSensors.StatusChanged += KinectSensorsStatusChanged; 
             if(_kinect != null) 

         static void KinectSensorsStatusChanged(object sender, StatusChangedEventArgs e) 
             Console.WriteLine("{0} - New Status: {1}", DateTime.Now.TimeOfDay.ToString(), e.Status); 
             _kinect = e.Sensor; 
             if (e.Sensor != null) 
                 Console.WriteLine("{0} - Sensor Status: {1}", DateTime.Now.TimeOfDay.ToString(), _kinect.Status); 
                 if (_kinect.Status == KinectStatus.Connected) 
                     Console.WriteLine("{0} - Sensor Started", DateTime.Now.TimeOfDay.ToString()); 
                 Console.WriteLine("{0} - No Sensor", DateTime.Now.TimeOfDay.ToString()); 


Contact Information:

The Discussion

  • User profile image


    The code seems to have a small error. I tried it, and while it does start, it does not report the status of my Kinect for Windows sensor. I think this *may* have something to do with line 27, where in the list of arguments for console.writeline there is "ect.Status". Did you mean e.Status, or _kinect.Status? Or is it something else entirely?

  • User profile image

    @Nerdenator: Good catch, thank you.

    Yep, there was a bug on line 27 (now fixed). I switched it to e.Status and it seems to work for me.

    In looking at the original post though, looks like the author later updated it to use _kinect.Status. Either one should work.

    (Just a side note, I cannot take any credit for this project/code. The original author,, deserves all the kudo's and credit, etc for it. I'm just the messenger...


Add Your 2 Cents