【发布时间】:2021-08-03 10:50:10
【问题描述】:
大家好,我的情况是我试图从控制台应用程序打印 PDF 文件,它是文件观察程序。 实际上,一旦在该文件夹中创建了 Xml 文件,我就会将 Xml 放在特定的物理路径中。文件观察器操作启动。 读取打印机名称和打印文件等 XML 内容。基于发送到打印机的那个文件。 我的问题是,如果我给多个请求,第一个或两个文件没有发送到打印机队列。立即给另一个多个请求,所有文件都发送到打印机队列。 15 或 30 分钟后出现相同的问题,第一个或两个文件未发送到打印机。 我的代码,
public static void FileWatcherfunction()
{
string strprintpath = ConfigurationManager.AppSettings["Schedulepath"];
strprintpath = strprintpath + @"\print";
//Console.WriteLine("config path:: "+ strprintpath);
Logger.Log("Print path : "+ strprintpath);
_fileWatcher = new FileSystemWatcher(strprintpath);
_fileWatcher.Created += new FileSystemEventHandler(_fileWatcher_Created);
_fileWatcher.Deleted += new FileSystemEventHandler(_fileWatcher_Deleted);
}
private static void _fileWatcher_Created(object sender, FileSystemEventArgs e)
{
Printfile(strPrinterName, strPrintFileName);
}
private static void Printfile(String strPrinterName, String strPrintFileName)
{
if (File.Exists(strPrintFileName))
{
Process p = new Process();
try
{
strFileType = strPrintFileName.Substring(strPrintFileName.Length - 3);
Logger.Log("strFileType:" + strFileType);
p.StartInfo.FileName = strPrintFileName;
p.StartInfo.Verb = "PrintTo";
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = "\"" + strPrinterName + "\"";
p.Start();
iStartProcId = p.Id;
Logger.Log("iStartProcId:"+ iStartProcId) ;
p.WaitForExit(15000);
Logger.Log("This document has been sent to the printer : " + strPrinterName);
p.EnableRaisingEvents = true;
// p.WaitForInputIdle();
if (strFileType.ToUpper() =="PDF")
{
Logger.Log("FileType is PDF: ");
if (!p.HasExited)
{
try
{
KillAdobe("AcroRd32", iStartProcId);
}
catch (Exception killex)
{
}
p.CloseMainWindow();
p.Close();
}
}
Logger.Log("Printing process completed");
}
catch (Exception exp)
{
KillAdobe("AcroRd32", iStartProcId);
Logger.Log("Error: Exception: " + exp.Message);
}
}
}
【问题讨论】:
标签: c# printing network-printers