private void DettachHookFromProcess()
        {
            if (captureProcess != null)
            {
                captureInterface.RemoteMessage -= this.CaptureInterfaceOnRemoteMessage;
                captureProcess.Dispose();
                captureProcess = null;
                this.attached  = false;
            }

            for (int i = 0; i < 2; i++)
            {
                if (this.sharedTexturesAccess[i] != null)
                {
                    this.sharedTexturesAccess[i].SafeMemoryMappedViewHandle.ReleasePointer();
                    this.sharedTexturesAccess[i].Dispose();
                    this.sharedTexturesAccess[i] = null;
                }

                if (this.sharedTextures[i] != null)
                {
                    bool locked = false;
                    try
                    {
                        locked = sharedMemMutexes[i].WaitOne(1000);
                    }
                    catch (AbandonedMutexException ex)
                    {
                        locked = true;
                    }
                    finally
                    {
                        this.sharedTextures[i].Dispose();
                        this.sharedTextures[i] = null;
                        if (locked)
                        {
                            sharedMemMutexes[i].ReleaseMutex();
                        }
                    }
                }
            }

            if (copyDataMemAccess != null)
            {
                copyDataMemAccess.SafeMemoryMappedViewHandle.ReleasePointer();
                copyDataMemAccess.Dispose();
                copyDataMemAccess = null;
            }
            if (copyDataMem != null)
            {
                copyDataMem.Dispose();
                copyDataMem = null;
            }
            // lastCaptured = -1;
        }
 public override void Stop()
 {
     _stopped = true;
     if (_capturedProcess != null)
     {
         _capturedProcess.CaptureInterface.Disconnect();
         _capturedProcess.Dispose();
     }
 }