string envelope_template = "temp.doc";
string envelope_printer = "printer"; //this is the destination printer
string invoice_printer = "printer"; //this is the default printer Word._Application wrdApp = null;
Word._Document wrdDoc = null;
Word.MailMerge wrdMailMerge; object oMissing = System.Reflection.Missing.Value;
object oFalse = false;
object oTrue = true;
object oNull = String.Empty; try
{
wrdApp = new Word.Application();
wrdApp.Visible = false;
wrdApp.ChangeFileOpenDirectory(Directory.GetCurrentDirectory());
object oEnvelopeTemplate = envelope_template;
wrdDoc = wrdApp.Documents.Add(ref oEnvelopeTemplate, ref oMissing,
ref oMissing, ref oMissing);
wrdMailMerge = wrdDoc.MailMerge; wrdMailMerge.OpenDataSource(
"wenben.txt",
ref oMissing, ref oMissing, ref oFalse, ref oTrue, ref oFalse,
ref oMissing, ref oMissing, ref oFalse, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdApp.ActivePrinter = envelope_printer;
wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter;
wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Execute(ref oFalse);
wrdApp.ActivePrinter = invoice_printer;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("MailMerge:" + "" + ex.Message);
}
finally
{
if (wrdDoc != null)
{
wrdDoc.Saved = false;
wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
wrdDoc = null;
} if (wrdApp != null)
{
wrdApp.Quit(ref oFalse, ref oMissing, ref oMissing);
wrdApp = null;
} wrdMailMerge = null; GC.Collect();
GC.WaitForPendingFinalizers(); GC.Collect();
GC.WaitForPendingFinalizers();
}
string envelope_printer = "printer"; //this is the destination printer
string invoice_printer = "printer"; //this is the default printer Word._Application wrdApp = null;
Word._Document wrdDoc = null;
Word.MailMerge wrdMailMerge; object oMissing = System.Reflection.Missing.Value;
object oFalse = false;
object oTrue = true;
object oNull = String.Empty; try
{
wrdApp = new Word.Application();
wrdApp.Visible = false;
wrdApp.ChangeFileOpenDirectory(Directory.GetCurrentDirectory());
object oEnvelopeTemplate = envelope_template;
wrdDoc = wrdApp.Documents.Add(ref oEnvelopeTemplate, ref oMissing,
ref oMissing, ref oMissing);
wrdMailMerge = wrdDoc.MailMerge; wrdMailMerge.OpenDataSource(
"wenben.txt",
ref oMissing, ref oMissing, ref oFalse, ref oTrue, ref oFalse,
ref oMissing, ref oMissing, ref oFalse, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdApp.ActivePrinter = envelope_printer;
wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter;
wrdMailMerge.SuppressBlankLines = true;
wrdMailMerge.Execute(ref oFalse);
wrdApp.ActivePrinter = invoice_printer;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("MailMerge:" + "" + ex.Message);
}
finally
{
if (wrdDoc != null)
{
wrdDoc.Saved = false;
wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
wrdDoc = null;
} if (wrdApp != null)
{
wrdApp.Quit(ref oFalse, ref oMissing, ref oMissing);
wrdApp = null;
} wrdMailMerge = null; GC.Collect();
GC.WaitForPendingFinalizers(); GC.Collect();
GC.WaitForPendingFinalizers();
}
为什么你要
GC.Collect();
GC.WaitForPendingFinalizers();
2次?