在我的程序中,我有以下代码片段:
private void button1_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
string strText = "";
foreach (object x in listBox1.Items)
{
strText = strText + x.ToString() + "\n";
}
myReader = new StringReader(strText);
try
{
if (printDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
这可以打印listBox1中的所有内容。
作为更新的一部分,我在代码的另一部分更改了SQL服务器引用,现在此部分返回“外部组件已抛出错误”。
我完全不知道从哪里开始,因为即使更改引用仍然会抛出异常。我甚至试过运行一个早先在早上工作的版本,但现在我得到了例外。
完整的异常详情:
System.Runtime.InteropServices.SEHException was unhandled
HResult=-2147467259
Message=External component has thrown an exception.
Source=System.Windows.Forms
ErrorCode=-2147467259
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.PrintDlgEx(PRINTDLGEX lppdex)
at System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, PRINTDLGEX data)
at System.Windows.Forms.PrintDialog.RunDialog(IntPtr hwndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
at System.Windows.Forms.CommonDialog.ShowDialog()
at McBeathTraining.GapCheck.button1_Click(Object sender, EventArgs e) in C:\Users\Benjamin.Roffey\Documents\Visual Studio 2010\Projects\McBeathTraining\McBeathTraining\GapCheck.cs:line 191
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
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.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.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 System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at McBeathTraining.Form1.GapCheck_Click(Object sender, EventArgs e) in C:\Users\Benjamin.Roffey\Documents\Visual Studio 2010\Projects\McBeathTraining\McBeathTraining\Form1.cs:line 96
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
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.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.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 System.Windows.Forms.Application.Run(Form mainForm)
at McBeathTraining.Program.Main() in C:\Users\Benjamin.Roffey\Documents\Visual Studio 2010\Projects\McBeathTraining\McBeathTraining\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
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 :(得分:1)
假设您隐藏的代码实际上没有抛出异常(特别是该对话框的打印事件),这种异常通常是因为公寓线程问题。您需要将调用STA
的线程设为 PUBNUB.init({
publish_key://my publish key,
subscribe_key://my subscrition key
});
。