/// <summary> /// 绘制 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MonitorUserControl_Paint(object sender, PaintEventArgs e) { if (_objRef == null) { return; } if (SM.TryEnter(_objRef)) { try { if (_bitmap == null) { return; } Point point = new Point(AutoScrollPosition.X, AutoScrollPosition.Y); e.Graphics.DrawImage(_bitmap, point); } finally { SM.Exit(_objRef); } } }
/// <summary> /// 屏幕 /// </summary> public void UpdateDisplay() { if (_objRef == null) { return; } if (SM.TryEnter(_objRef)) { try { byte[] bitmapBytes = _objRef.GetDesktopBitmapBytes(); if (bitmapBytes.IsNullOrEmpty()) { return; } var stream = new MemoryStream(bitmapBytes, false); _bitmap = (Bitmap)Image.FromStream(stream); Point point = new Point(AutoScrollPosition.X, AutoScrollPosition.Y); CreateGraphics().DrawImage(_bitmap, point); } finally { SM.Exit(_objRef); } } }
public void TestMonitorWithLockTaken() { this.Test(() => { object obj = new object(); bool lockTaken = false; Monitor.TryEnter(obj, ref lockTaken); if (lockTaken) { Monitor.Exit(obj); } Specification.Assert(lockTaken, "lockTaken is false"); }, GetConfiguration()); }
public static bool TryEnter(object obj, TimeSpan timeout) { return(SMonitor.TryEnter(obj, timeout)); }
public static bool TryEnter(object obj) { return(SMonitor.TryEnter(obj)); }