Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Solution1.AutomateWord 阐述了通过Microsoft Word主要的互用组件(PIA)
            // 自动化Word应用程序, 并且将每个COM访问对象分配给一个新的变量, 使用户
            // 最终可以通过调用Marshal.FinalReleaseComObject方法释放这些变量的过程.

            Solution1.AutomateWord();

            Console.WriteLine();

            // Solution2.AutomateWord阐述了通过Microsoft Word主要的互用组件(PIA)
            // 自动化Word应用程序, 在自动化方法退出堆栈后执行垃圾收集器(此时RCW
            // 对象不再被引用),从而清除RCW并释放COM对象的过程.

            Solution2.AutomateWord();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // Solution1.AutomateWord demonstrates automating Microsoft Word
            // application by using Microsoft Word PIA and explicitly
            // assigning each COM accessor object to a new varaible that you
            // would explicitly call Marshal.FinalReleaseComObject to release
            // it at the end.
            Solution1.AutomateWord();

            Console.WriteLine();

            // Solution2.AutomateWord demonstrates automating Microsoft Word
            // application by using Microsoft Word PIA and forcing a garbage
            // collection as soon as the automation function is off the stack
            // (at which point the RCW objects are no longer rooted) to clean
            // up RCWs and release COM objects.
            Solution2.AutomateWord();
        }