void FoscamCameraPreview_Unloaded(object sender, RoutedEventArgs e)
 {
     device.CameraInfo.PropertyChanged -= OnCameraPropertyChanged;
     device.Error          -= OnDeviceError;
     device.FrameAvailable -= OnFrameAvailable;
     device.StopStream();
     unloaded = true;
     StopUpdateTimer();
 }
        private void Reconnect()
        {
            if (device != null)
            {
                device.StopStream();

                var camera = device.CameraInfo;
                if (camera.StaticImageUrl != null)
                {
                    ShowStaticImage(camera.StaticImageUrl);
                    ShowError(camera.StaticError);
                }
                else if (camera.UpdatingFirmware || camera.Rebooting)
                {
                    ShowStaticImage("ms-appx:/Assets/Gear.png");
                }
                else
                {
                    device.StartJpegStream(this.Dispatcher);
                }
            }
        }