public static ScreenshotResponse GetScreenshotSynchronous(Int32 clientPID, ScreenshotRequest screenshotRequest, TimeSpan timeout) { object srLock = new object(); ScreenshotResponse sr = null; ScreenshotRequestResponseNotification srrn = delegate(Int32 cPID, ResponseStatus status, ScreenshotResponse screenshotResponse) { Interlocked.Exchange(ref sr, screenshotResponse); }; DateTime startRequest = DateTime.Now; AddScreenshotRequest(clientPID, screenshotRequest, srrn); // Wait until the response has been returned while (true) { Thread.Sleep(10); if (sr != null) { break; } // Break if timed out (will result in a null return value) if (DateTime.Now - startRequest > timeout) { return(null); } } return(sr); }
/// <summary> /// Set the screenshot response for the given process Id /// </summary> /// <param name="clientPID"></param> /// <param name="screenshotResponse"></param> public static void SetScreenshotResponse(Int32 clientPID, ScreenshotResponse screenshotResponse) { try { lock (_screenshotRequestNotifications) { if (_screenshotRequestNotifications[clientPID] != null) { _screenshotRequestNotifications[clientPID](clientPID, ResponseStatus.Complete, screenshotResponse); _screenshotRequestNotifications.Remove(clientPID); } } } catch { } }
/// <summary> /// Set the screenshot response for the given process Id /// </summary> /// <param name="clientPID"></param> /// <param name="screenshotResponse"></param> public static void SetScreenshotResponse(Int32 clientPID, ScreenshotResponse screenshotResponse) { try { lock (_screenshotRequestNotifications) { if (_screenshotRequestNotifications[clientPID] != null) { _screenshotRequestNotifications[clientPID](clientPID, ResponseStatus.Complete, screenshotResponse); _screenshotRequestNotifications.Remove(clientPID); } } } catch { } }