2013-02-14 26 views
1

我跑了一些非常基本的打印碼:(使用.NET 4.0,VS 2012,Windows 8中)System.Drawing.Printing:RPC服務器不可用

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: 
+0

System.Drawing.Printing和Windows打印API都不使用RPC。您需要先查看打印機驅動程序。 – 2013-02-14 12:19:20

回答

4

這實在是一個長鏡頭 - 但我認爲你應該檢查,如果你要打印到打印機你以爲你是打印到..;)

(檢查是否打印正確打印機並打開)

+0

其實你的評論幫助!突然,錯誤消失了!當時「默認打印機」未連接到我的電腦....仍然不明白錯誤發生的原因,但現在,至少該問題消失了。 :) 謝謝!! – 2013-02-16 21:20:38

+0

說實話,這不是'真的'一炮打響.. :)你試圖打印,只有RPC在這種情況下是你的打印機驅動程序試圖發送命令到你的服務器(打印機),這可能是無法使用的。「消息= RPC服務器不可用「 – 2013-02-17 02:43:13

+0

對我而言,重新啓動打印後臺處理程序服務可解決問題 – hillstuk 2015-06-02 15:30:18