可以计算单词文档“打开”(通常双击文档的操作)到Word中文档的有效视图所用的时间吗?
我认为我的时间跨度的开始可能就是这个过程。应用程序的开始。 但是,我怎么知道文档何时在Microsoft Word中有效打开?
答案 0 :(得分:1)
Interop是同步的,所以你应该能够这样做:
string path = "";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
var excel = new Microsoft.Office.Interop.Excel.Application();
excel.Workbooks.Open(path, Type.Missing, false, Type.Missing, Type.Missing,
Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
Console.ReadKey();