private void buttonDisconnect_Click(object sender, EventArgs e) { if (_kCubeDCServoMotor == null) { MessageBox.Show("Not connected to device"); return; } // All of this operation has been placed inside a "catch-all" exception // handler. Normally you would catch the more specific exceptions that // the API call might throw (details of which can be found in the // Kinesis .NET API document). try { // Shuts down this device and frees any resources it is using. _kCubeDCServoMotor.ShutDown(); _kCubeDCServoMotor = null; } catch (Exception ex) { MessageBox.Show("Unable to disconnect from device\n" + ex); } }