title: How to close the handle of the Kinect USB port to prevent VisualStudio to crash?
body: <p>I'm working on the Kinect, and sporadically the Kinect makes Visual Studio Crash.</p>
  
  <p>It's happening when I call the <code>kinectSensor.Start()</code> method after debugging I found out that the <strong><em>Kinect is already in use in another process</em></strong>.</p>
  
  <p><strong>But no other processes is using the Kinect!</strong> 
  It happened one time on the morning after booting my machine and launching the app. 
  But most of the time it occurs when I launch the Kinect App (in debugging mode in VisualStudio 2010), I stop the application and after some code modification I re-launch the app and that time it doesn't work, I've got the above exception and after 2sec Visual Studio crashes.</p>
  
  <p>Moreover I check if the Kinect is already running and this is not the case (below the state of the Kinect sensor during debugging):</p>
  
  <p><img src="https://i.stack.imgur.com/rNGu1.png" alt="state of kinect sensor (debug mode)"></p>
  
  <p>The weirdest thing above all is that sometimes it works fine for weeks, and after that it makes that thing  for two days every two/three launches of the app.</p>
  
  <p>The only solution I found on the subject is from one guy with a very similar problem (the only one on the internet?) : <a href="http://imadelayyan.com/?p=8" rel="nofollow noreferrer">Imad Elayyan</a></p>
  
  <p>When I launch <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="nofollow noreferrer">Process Explorer</a> I found the exact same problem of USB port handling (shown on the photo), a mutant process which is not terminated when we close the app.</p>
  
  <p><img src="https://i.stack.imgur.com/xjMHq.png" alt="mutant process for the USB handle of the Kinect"></p>
  
  <p>But his solution is <em>not really</em> a long term solution: I have to kill manually the mutant and re-start VisualStudio. Sometimes I have to restart VS 20 times on the morning...</p>
  
  <p><strong><em>Is there a way to properly close that handle of the usb port (in code?) so that when I close the app it terminate that handle and doesn't makes VS crash anymore?</em></strong></p>
  
  <p>Any help would be appreciated, it is really puzzling me and it drives me crazy.</p>
  
  <p><strong>Additional information</strong>: </p>
  
  <p>i'm using the <em>SDK1.5 + Kinect for Windows</em> but it was also the case with the <em>SDK1.0 + Kinect XBox360</em></p>
  
  <p>I've already try to debug VS with another instance of VS.</p>