private TResult _ownerInvoke <TResult>(Fn <TResult> method) { if (owner.InvokeRequired) { return((TResult)owner.Invoke(method)); } else { return(method()); } }
private void _document_PrintPage(object sender, PrintPageEventArgs e) { // running on a seperate thread, so we invoke _webFramePrivate // methods on the owners ui thread if (_printGfx == null) { // initialise printing _printGfx = e.Graphics; _hDC = _printGfx.GetHdc().ToInt32(); _owner.Invoke(new MethodInvoker(delegate() { _webFramePrivate.setInPrintingMode(1, _hDC); })); _nPages = (uint)_owner.Invoke( new GetPrintedPageCountDelegate(delegate() { return(_webFramePrivate.getPrintedPageCount(_hDC)); })); _page = 1; } _owner.Invoke(new MethodInvoker(delegate() { _webFramePrivate.spoolPages(_hDC, _page, _page, IntPtr.Zero); })); ++_page; if (_page <= _nPages) { e.HasMorePages = true; } else { _owner.Invoke(new MethodInvoker(delegate() { _webFramePrivate.setInPrintingMode(0, _hDC); })); e.HasMorePages = false; _printGfx = null; _nPages = 0; } }