예제 #1
0
 private void SetListBox(string[] input, ListBox target)
 {
     _safeInvoker.Invoke(delegate
     {
         target.DataSource = input;
     });
 }
예제 #2
0
        private static void TryGetScreenshot(Control controlForScreenshotting)
        {
            if (controlForScreenshotting == null)
            {
                Logger.WriteEvent("Bloom was unable to create a screenshot as no active form could be found");
                return;
            }
            _takingScreenshotLock.Wait();               // Acquire the lock

            try
            {
                SafeInvoke.Invoke("Screen Shot", controlForScreenshotting, false, true, () =>
                {
                    try
                    {
                        // I got tired of landing here in the debugger so I'm avoiding the exception
                        if (controlForScreenshotting.Bounds.Width == 0)
                        {
                            ResetScreenshotFile();
                        }
                        else
                        {
                            var bounds     = controlForScreenshotting.Bounds;
                            var screenshot = new Bitmap(bounds.Width, bounds.Height);
                            using (var g = Graphics.FromImage(screenshot))
                            {
                                if (controlForScreenshotting.Parent == null)
                                {
                                    g.CopyFromScreen(bounds.Left, bounds.Top, 0, 0,
                                                     bounds.Size);                                    // bounds already in screen coords
                                }
                                else
                                {
                                    g.CopyFromScreen(
                                        controlForScreenshotting.PointToScreen(new Point(bounds.Left, bounds.Top)),
                                        Point.Empty, bounds.Size);
                                }
                            }

                            _reportInfo.ScreenshotTempFile = TempFile.WithFilename(ScreenshotName);
                            RobustImageIO.SaveImage(screenshot, _reportInfo.ScreenshotTempFile.Path,
                                                    ImageFormat.Png);
                        }
                    }
                    catch (Exception e)
                    {
                        ResetScreenshotFile();
                        Logger.WriteError("Bloom was unable to create a screenshot.", e);
                    }
                    finally
                    {
                        // Release lock (Unblock others)
                        if (_takingScreenshotLock.CurrentCount == 0)
                        {
                            _takingScreenshotLock.Release();
                        }
                    }
                }
                                  );
            }
            catch (Exception error)
            {
                // Release lock (Unblock others)
                if (_takingScreenshotLock.CurrentCount == 0)
                {
                    _takingScreenshotLock.Release();
                }

                Debug.Fail("This error would be swallowed in release version: " + error.Message);
                SIL.Reporting.Logger.WriteEvent("**** " + error.Message);
            }
        }