Пример #1
0
 public void Stop()
 {
     _running = false;
     Task.WaitAll(_task);
     _wiring.Dispose();
     _wiring = null;
 }
Пример #2
0
 private void ProcessFrame()
 {
     while (_running)
     {
         var depth      = Depth;
         var saturation = Saturation;
         try
         {
             if (_wiring == null)
             {
                 _wiring = new Wiring();
                 // Adding one because we'll be giving the verticalSegments the corners, so the top segments need to skip the leftmost space.
                 _horizontalSegments = CreateSegmentsArray(LEDs.Counts[Strip.Top] + 1, _wiring.Width);
                 _verticalSegments   = CreateSegmentsArray(LEDs.Counts[Strip.Left], _wiring.Height);
             }
             (var changes, var screenResource) = GetNextFrame();
             try
             {
                 if (changes)
                 {
                     ProcessScreen(screenResource, depth, saturation);
                 }
             }
             finally
             {
                 screenResource.Dispose();
                 _wiring.OutputDuplication.ReleaseFrame();
             }
         }
         // On exception, if it's an expectable type (the output needs to be reacquired, or we ran into the timeout),
         // then we just give up on this pass and try again later.
         catch (SharpDXException e)
         {
             if (e.ResultCode.Code != SharpDX.DXGI.ResultCode.WaitTimeout.Result.Code)
             {
                 if (e.ResultCode.Code == SharpDX.DXGI.ResultCode.AccessLost.Result.Code ||
                     e.ResultCode.Code == SharpDX.DXGI.ResultCode.AccessDenied.Result.Code ||
                     e.ResultCode.Code == SharpDX.Result.AccessDenied.Result.Code)
                 // Ignoring access denied, as it should be 'self-curing', and access lost just means we need to renew our duplication.
                 {
                     _wiring?.Dispose();
                     _wiring = null;
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         Thread.Sleep(Interval);
     }
 }