private void SwitchStream(bool KeyDown) { if (client != null && KeyDown) { if (client.IsStreamOn) { if (client.StreamOff()) { img_stream_gray.Visibility = Visibility.Visible; } } else { if (client.StreamOn()) { if (!videoReceiverStarted) { // Must start on new thread otherwise wrong keyevent is raised! new Thread(() => { if (StartVideoReceiver(640, 480)) { videoReceiverStarted = true; } }).Start(); } img_stream_gray.Visibility = Visibility.Collapsed; } } } }