public void Disconnect() { if (m_connected) { m_connected = false; try { DisableProfiling(); /* When this 'flush' returns, all data in the stream should have been sent out. * so setting the end of stream marker will not cause race conditions with the WP packet receiving thread. */ m_engine.FlushProfilingStream(); } catch { /* Ignore errors if we are already disconnected from the device. */ } m_incomingStream.MarkStreamEnd(); } }