private void CloseContext() { if (FContext != null) { FContext.StopGeneratingAll(); FContext.ErrorStateChanged -= FContext_ErrorStateChanged; if (FDepthGenerator != null) { FDepthGenerator.Dispose(); FDepthGenerator = null; } FContext.Release(); FContext = null; } }
private void CloseContext() { if (FUpdater != null && FUpdater.IsAlive) { //wait for threadloop to exit FRunning = false; FUpdater.Join(); } if (FContext != null) { //FContext.WaitAndUpdateAll(); FContext.StopGeneratingAll(); FContext.ErrorStateChanged -= FContext_ErrorStateChanged; if (FHandGenerator != null) { FHandGenerator.HandCreate -= FHands_HandCreate; FHandGenerator.HandDestroy -= FHands_HandDestroy; FHandGenerator.HandUpdate -= FHands_HandUpdate; FHandGenerator.Dispose(); FHandGenerator = null; } if (FDepthGenerator != null) { FDepthGenerator.Dispose(); } if (FImageGenerator != null) { FImageGenerator.Dispose(); } FTrackedStartPositions.Clear(); FTrackedHands.Clear(); FContext.Release(); FContext = null; } Marshal.FreeCoTaskMem(FBufferedImage); }