Silverlight Excel Release process

How to release COM objects in Silverlight 4 这个网上有个例子

 

    private void Button_Click(object sender, RoutedEventArgs e)
   
{
       
using (dynamic app = AutomationFactory.CreateObject("Excel.Application"))
       
{
           
using (dynamic book = app.Workbooks.Add())
           
{
               
using (dynamic sheet = app.ActiveSheet())
               
{ }
                book
.Close();
           
}
            app
.Quit();
       
}; 
        GC
.Collect();
   
}
这个是可以回收资源的. 但是如果把 dynamic book = app.Workbooks.Add() 该为 dynamic workBooks = excel.Workbooks._Open(@"D:\test.xls", Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)

这时名次运行完, 都会有一个Excel进程不能释放.(勉强可以接受). 以后再试试其它方法.

posted @ 2012-08-16 18:57  Ken-Cai  阅读(190)  评论(0编辑  收藏  举报