private void HandleCaptureRequestThread() { try { if (Request == null) { return; } lock (renderTargetLock) { var size = height * pitch; var bdata = new byte[size]; Marshal.Copy(surfaceDataPointer, bdata, 0, size); var retrieveParams = new RetrieveImageDataParams() { RequestId = Request.RequestId, Data = bdata, Width = width, Height = height, Pitch = pitch }; var t = new Thread(RetrieveImageData); t.Start(retrieveParams); } } catch (Exception ex) { DebugMessage(ex.ToString()); } finally { Request = null; } }
/// <summary> /// ParameterizedThreadStart method that places the image data from the stream into a byte array and then sets the Interface screenshot response. This can be called asynchronously. /// </summary> /// <param name="param">An instance of RetrieveImageDataParams is required to be passed as the parameter.</param> /// <remarks>The stream object passed will be closed!</remarks> void RetrieveImageData(object param) { RetrieveImageDataParams retrieveParams = (RetrieveImageDataParams)param; try { ProcessCapture(retrieveParams.Stream, retrieveParams.RequestId); } finally { retrieveParams.Stream.Close(); } }
protected void ProcessCapture(RetrieveImageDataParams data) { var screenshot = new Screenshot(data.RequestId, data.Data, data.Width, data.Height, data.Pitch); try { Interface.SendScreenshotResponse(screenshot); } catch (RemotingException ex) { TraceMessage("RemotingException: " + ex.Message); screenshot.Dispose(); // Ignore remoting exceptions // .NET Remoting will throw an exception if the host application is unreachable } catch (Exception e) { DebugMessage(e.ToString()); } }
/// <summary> /// Copies the _renderTarget surface into a stream and starts a new thread to send the data back to the host process /// </summary> void ProcessRequest() { if (Request != null) { Rectangle region = Request.RegionToCapture; // Prepare the parameters for RetrieveImageData to be called in a separate thread. RetrieveImageDataParams retrieveParams = new RetrieveImageDataParams(); // After the Stream is created we are now finished with _renderTarget and have our own separate copy of the data, // therefore it will now be safe to begin a new thread to complete processing. // Note: RetrieveImageData will take care of closing the stream. // Note 2: Surface.ToStream is the slowest part of the screen capture process - the other methods // available to us at this point are _renderTarget.GetDC(), and _renderTarget.LockRectangle/UnlockRectangle if (Request.RegionToCapture.Width == 0) { // The width is 0 so lets grab the entire surface retrieveParams.Stream = Surface.ToStream(_renderTarget, ImageFileFormat.Bmp); } else if (Request.RegionToCapture.Height > 0) { retrieveParams.Stream = Surface.ToStream(_renderTarget, ImageFileFormat.Bmp, new SharpDX.Rectangle(region.Left, region.Top, region.Right, region.Bottom)); } if (retrieveParams.Stream != null) { // _screenshotRequest will most probably be null by the time RetrieveImageData is executed // in a new thread, therefore we must provide the RequestId separately. retrieveParams.RequestId = Request.RequestId; // Begin a new thread to process the image data and send the request result back to the host application Thread t = new Thread(new ParameterizedThreadStart(RetrieveImageData)); t.Start(retrieveParams); } } }
protected void ProcessCapture(RetrieveImageDataParams data) { var screenshot = new Screenshot(data.RequestId, data.Data, data.Width, data.Height, data.Pitch); try { this.Interface.SendScreenshotResponse(screenshot); } catch (RemotingException ex) { this.TraceMessage("RemotingException: " + ex.Message); screenshot.Dispose(); // Ignore remoting exceptions // .NET Remoting will throw an exception if the host application is unreachable } catch (Exception e) { this.DebugMessage(e.ToString()); } finally { } }
/// <summary> /// Copies the _renderTarget surface into a stream and starts a new thread to send the data back to the host process /// </summary> void ProcessRequest() { if (Request != null) { Rectangle region = Request.RegionToCapture; // Prepare the parameters for RetrieveImageData to be called in a separate thread. RetrieveImageDataParams retrieveParams = new RetrieveImageDataParams(); // After the Stream is created we are now finished with _renderTarget and have our own separate copy of the data, // therefore it will now be safe to begin a new thread to complete processing. // Note: RetrieveImageData will take care of closing the stream. // Note 2: Surface.ToStream is the slowest part of the screen capture process - the other methods // available to us at this point are _renderTarget.GetDC(), and _renderTarget.LockRectangle/UnlockRectangle if (Request.RegionToCapture.Width == 0) { // The width is 0 so lets grab the entire surface retrieveParams.Stream = Surface.ToStream(_renderTarget, ImageFileFormat.Bmp); } else if (Request.RegionToCapture.Height > 0) { retrieveParams.Stream = Surface.ToStream(_renderTarget, ImageFileFormat.Bmp, new SharpDX.Rectangle(region.X, region.Y, region.Width, region.Height)); } if (retrieveParams.Stream != null) { // _screenshotRequest will most probably be null by the time RetrieveImageData is executed // in a new thread, therefore we must provide the RequestId separately. retrieveParams.RequestId = Request.RequestId; // Begin a new thread to process the image data and send the request result back to the host application Thread t = new Thread(new ParameterizedThreadStart(RetrieveImageData)); t.Start(retrieveParams); } } }
private void HandleCaptureRequestThread() { try { if (Request == null) { return; } lock (renderTargetLock) { var size = height * pitch; var bdata = new byte[size]; Marshal.Copy(surfaceDataPointer, bdata, 0, size); var retrieveParams = new RetrieveImageDataParams() { RequestId = Request.RequestId, Data = bdata, Width = width, Height = height, Pitch = pitch }; var t = new Thread(RetrieveImageData); t.Start(retrieveParams); } } catch (Exception ex) { DebugMessage(ex.ToString()); } finally { Request = null; } }