c# - 系统.绘图.打印 : The RPC server is unavailable

标签 c# winapi printing controls rpc

我正在运行一些非常基本的打印代码:(使用 .net 4.0、VS 2012、Windows 8)

var bitmap = new Bitmap(control.Width, control.Height);

control.DrawToBitmap(bitmap, new Rectangle(0, 0, control.Width, control.Height));

var pd = new PrintDocument();

pd.PrintPage += (s, e) => e.Graphics.DrawImage(bitmap, 100, 100);
pd.Print();

它抛出一个错误:

System.ComponentModel.Win32Exception was unhandled
HResult=-2147467259
Message=The RPC server is unavailable
  Source=System.Drawing
  ErrorCode=-2147467259
  NativeErrorCode=1722
  StackTrace:
   at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
   at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e)
   at System.Drawing.Printing.PrintController.Print(PrintDocument document)
   at System.Drawing.Printing.PrintDocument.Print()
   at FrogJump.Form1.PrintControl(Control control) in e:\Univ\S13\AI\FrogJump\FrogJump\Form1.cs:line 120
   at FrogJump.Form1.btnPrint_Click(Object sender, EventArgs e) in e:\Univ\S13\AI\FrogJump\FrogJump\Form1.cs:line 108
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at FrogJump.Program.Main() in e:\Univ\S13\AI\FrogJump\FrogJump\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: 

最佳答案

这真的是一个远景 - 但我认为您应该检查您是否正在打印到您认为正在打印到的打印机.. ;)

(检查您是否打印到正确的打印机并且它已打开)

关于c# - 系统.绘图.打印 : The RPC server is unavailable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14873481/

相关文章:

c# - azure-functions 中的程序集引用

printing - 如何限制 Fortran 中每行要打印的字符数?

python - 使用Python打印模式 'FUN'

c++ - SendInput() 不等于在 C++ 键盘上手动按键?

c++ - 无框架 Qt 窗口 (win32) 中错误的窗口绘制行为

delphi - BitBlt Printer.Canvas 到 TBitMap 显示为纯白色

c# - 如何制作单个实例表单(不是应用程序)?

c# - 在 wpf 中重新加载图像

c# - 在循环中使用 NEW 时,将项目添加到对象的 LIST<> 会导致重复的对象

c++ - 多次复制 Windows 桌面