C#使用Process打印导致的问题
我现在准备使用默认打印机打印WORD文档,但是在实际环境中使用反映说一旦打印卡死,会导致后面的操作无法进行
这是我自己写的一段测试打印的代码,打印部分大致与实际相同
string filename = @"C:\test.docx";
pro = new System.Diagnostics.Process();
pro.StartInfo.CreateNoWindow = true;
pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pro.StartInfo.UseShellExecute = true;
pro.StartInfo.FileName = filename;
pro.StartInfo.Verb = "print";
pro.Start();
MessageBox.Show("");//测试用的提示语句
public partial class Form1 : Form
{
System.Diagnostics.Process pro;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Print();
}
private void Print()
{
Thread t = new Thread(delegate()
{
string filename = @"C:\test.docx";
pro = new System.Diagnostics.Process();
pro.StartInfo.CreateNoWindow = true;
pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pro.StartInfo.UseShellExecute = true;
pro.StartInfo.FileName = filename;
pro.StartInfo.Verb = "print";
pro.Start();
MessageBox.Show("");
});
t.IsBackground = true;
t.Start();
}
private void button2_Click(object sender, EventArgs e)
{
if (pro != null)
{
pro.Kill();
pro = null;
}
}
}
if((@object["CommandLine"].ToString().Index("test.docx")>=0) p.Kill();
}
}
}
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/