在Interop上设置定时器 [英] Set Timer on Interop

查看:98
本文介绍了在Interop上设置定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我有以下代码,我用于迁移

Dear All,

I have following code, Am using for migration

object readOnly = false;
object isVisible = true; 
Word.Application app = new Word.Application();
app.WindowState = Word.WdWindowState.wdWindowStateMaximize;
app.Visible = true;
Word.Document doc = app.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
doc.Activate();
doc.Save();
doc.Close(ref missing, ref missing, ref missing);
app.Quit(ref missing, ref missing, ref missing);



有时文档包含一些错误,因此文档无法执行保存操作,所以我需要花一些时间来执行doc。 save(),如果它没有完成意味着我需要终止进程,并继续下一次迭代。请给出一些想法来实现它



预付谢谢

蝎子



已添加代码块[/ Edit]


Sometimes documents contains some error so document cant able do the save operation, So i need to give some time to execute doc.save() , if it doesnt complete means i need to kill the process, and continue next iteration. Please give some ideas to achieve it

Thanks in Advance
Scorpion

Code block added[/Edit]

推荐答案

尝试使用 try ... catch

Try using try...catch :
object readOnly = false;
object isVisible = true; 
Word.Application app = new Word.Application();
try
{
  app.WindowState = Word.WdWindowState.wdWindowStateMaximize;
  app.Visible = true;
 Word.Document doc = app.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref    missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
  doc.Activate();
  doc.Save();
  doc.Close(ref missing, ref missing, ref missing);
}
catch(Exception ex)
{
  // log your error here
}
finaly
{
  app.Quit(ref missing, ref missing, ref missing);
}


在我看来,您需要在开始保存文档之前验证表单字段。我不知道你的要求,所以我不能帮助你。您可以在此处找到一些有用的信息:

http://www.gmayor.com/formfieldmacros。 htm [ ^ ]

http://word.mvps.org/faqs/tblsfldsfms/ValidateFFields.htm [ ^ ]



有关MS Word 2010开发人员参考的更多信息: http: //msdn.microsoft.com/en-us/library/office/ee861527%28v=office.14%29.aspx [ ^ ]
In my opinion you need to validate form fields before you start saving document. I don''t know your requirements, so i can''t help you more. Some useful information you''ll find here:
http://www.gmayor.com/formfieldmacros.htm[^]
http://word.mvps.org/faqs/tblsfldsfms/ValidateFFields.htm[^]

More about MS Word 2010 developer reference: http://msdn.microsoft.com/en-us/library/office/ee861527%28v=office.14%29.aspx[^]


这篇关于在Interop上设置定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆