现在的方法是在窗体的线程上执行委托,但自动打印一段时间后程序直接卡死,请大家帮看下问题出在哪,或怎么优化:
///在拥有此控件的基础窗口句柄的线程上执行指定的委托。
private void PointDelegate()
{
this.Invoke(new PointInvokeDelegate(AutoPoint));
}
private void AutoPoint()
{
var loResult = moDao.GetNeedPointStu(); //获取待打印的学生名单
foreach(var stu in loResult)
{
//执行打印
PrintReport(stu.IDCARDNO, DateTime.Now.ToString(“yyyy-MM-dd”));
Thread.Sleep(10000);
return;
}
}
private void PrintReport(string vsIDCardNo, string vsTestDate)
{
this.PrintDocAssign.PrintController = new StandardPrintController();
msIDCardNo = vsIDCardNo;
msTestDate = vsTestDate;
///在拥有此控件的基础窗口句柄的线程上执行指定的委托。
private void PointDelegate()
{
this.Invoke(new PointInvokeDelegate(AutoPoint));
}
private void AutoPoint()
{
var loResult = moDao.GetNeedPointStu(); //获取待打印的学生名单
foreach(var stu in loResult)
{
//执行打印
PrintReport(stu.IDCARDNO, DateTime.Now.ToString(“yyyy-MM-dd”));
Thread.Sleep(10000);
return;
}
}
private void PrintReport(string vsIDCardNo, string vsTestDate)
{
this.PrintDocAssign.PrintController = new StandardPrintController();
msIDCardNo = vsIDCardNo;
msTestDate = vsTestDate;
this.PrintDocAssign.PrintPage += PrintDocAssign_PrintPage;
foreach (System.Drawing.Printing.PaperSize ps in PrintDocAssign.PrinterSettings.PaperSizes)
{
if (ps.PaperName == “A4”)
{
PrintDocAssign.PrinterSettings.DefaultPageSettings.PaperSize = ps;
PrintDocAssign.DefaultPageSettings.PaperSize = ps;
}
}
mbIfAutoPrint = true;
this.PrintDocAssign.Print(); //开始打印进程
moDao.SetPointZT(msIDCardNo, msTestDate);
}
}
解决方案
40
private void AutoPoint()
{
var loResult = moDao.GetNeedPointStu(); //获取待打印的学生名单
foreach(var stu in loResult)
{
//执行打印
PrintReport(stu.IDCARDNO, DateTime.Now.ToString(“yyyy-MM-dd”));
Thread.Sleep(10000);
return;
}
}
这个foreach、睡眠10秒和return,你确定是循环而又只打印一次?
假如是等待打印完毕,可以捕捉打印完毕事件,然后开始下一次打印,或使用打印队列。
{
var loResult = moDao.GetNeedPointStu(); //获取待打印的学生名单
foreach(var stu in loResult)
{
//执行打印
PrintReport(stu.IDCARDNO, DateTime.Now.ToString(“yyyy-MM-dd”));
Thread.Sleep(10000);
return;
}
}
这个foreach、睡眠10秒和return,你确定是循环而又只打印一次?
假如是等待打印完毕,可以捕捉打印完毕事件,然后开始下一次打印,或使用打印队列。