Example #1
0
        public void Dispose()
        {
            _cancellationTokenSource.Cancel();
            _updateTask = null;

            _screenCapture.Dispose();
        }
Example #2
0
 private void InitScreenCapture()
 {
     if (_screenCapture != null && !_screenCapture.IsDisposed())
     {
         // Screen capture already initialized. Ignoring request.
         return;
     }
     try
     {
         LOG.Info($"{this}: Initializing screen capture");
         _screenCapture.Initialize();
         LOG.Info($"{this}: Screen capture initialized");
     }
     catch (Exception ex)
     {
         _screenCapture?.Dispose();
         throw new Exception("Failed to initialize screen capture: " + ex.Message, ex);
     }
 }
Example #3
0
 private static void TryStartCapture()
 {
     try // Properly dispose screenCapture object when turning off capture
     {
         StartCapture();
     }
     finally
     {
         _screenCapture.Dispose();
     }
     LOG.Info("Screen Capture finished");
     ToggleCapture(CaptureCommand.OFF);
 }
Example #4
0
        private static void StartCapture()
        {
            int captureAttempt = 1;

            while (_captureEnabled)
            {
                try // This block will help retry capture before giving up
                {
                    InitScreenCapture();
                    InitProtoClient();
                    TransmitNextFrame();
                    _screenCapture.DelayNextCapture();

                    // Reset attempt count
                    captureAttempt = 1;
                }
                catch (Exception ex)
                {
                    LOG.Error($"Exception in screen capture attempt: {captureAttempt}", ex);
                    if (captureAttempt > AppConstants.REINIT_CAPTURE_AFTER_ATTEMPTS)
                    {
                        // After a few attempt, try disposing screen capture object as well
                        _screenCapture?.Dispose();
                        LOG.Info("Will re-initialize screen capture on retry");
                    }
                    if (++captureAttempt == AppConstants.MAX_CAPTURE_ATTEMPTS)
                    {
                        LOG.Error("Max screen capture attempts reached. Giving up.");
                        NotificationUtils.Error(ex.Message);
                        return;
                    }
                    else
                    {
                        LOG.Info("Waiting before next screen capture attempt");
                        Thread.Sleep(AppConstants.CAPTURE_FAILED_COOLDOWN_MILLIS);
                    }
                }
            }
        }
Example #5
0
 public void Dispose()
 {
     _streamer.Dispose();
     _capture.Dispose();
 }
 private static void DisposeScreenCapture()
 {
     _screenCapture?.Dispose();
     _screenCapture     = null;
     _lastScreenCapture = null;
 }