最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
.net中清除EXCEL进程最有效的方法
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
1、对excel操作做成一个函数,然后调用此函数。在函数中调用GC.Collect();无用,因为GC不回收调用自己的那一段代码块!
2、在函数的下面调用GC.Collect();语句。你会发现EXCEL进程没有了!
例如:
private void Import() {
Excel.Application myExcel = new Excel.Application();
myExcel.Workbooks.Add(openFileDialog1.FileName);
//........
//读取EXCEL文件,导入到数据库.
//清除excel垃圾进程
myExcel.Workbooks.Close();
myExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
myExcel = null;
}
private void ExcelImport() {
Import();
GC.Collect();
}
//以下按button1按钮,使用多线程读取EXCEL文件,导入到数据库.
private void button1_Click(object sender, System.EventArgs e) {
if(openFileDialog1.ShowDialog() == DialogResult.OK) {
System.Threading.Thread t=new System.Threading.Thread(new System.Threading.ThreadStart(ExcelImport));
t.Start();
}
}
-
上一个: 用.NET创建Windows服务
相关文章
- 用ado.net对word,excel进行存取 01-19
- 用VB.NET和Excel排生产计划 01-12
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18