一个结束excel线程出错的问题!!!!
/*******************first***********************/System.Threading.Thread t = null;
try
{
t = new System.Threading.Thread(new System.Threading.ThreadStart(excel.GetDataByReadExcelByTest));
t.Start();
t.Join();
}
catch(Exception ex)
{
throw ex;
}
finally
{
t.Abort();
}
/*********************second********************/
public void GetDataByReadExcelByTest()
{
AllTest_GetDataByReadExcel();
GC.Collect();
}
/****************thrid*********************/
private void AllTest_GetDataByReadExcel()
{
Excel.Application excel = null;
try
{
excel = new Excel.Application();
excel.Visible = false;
excel.UserControl = false;
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook workbook=workbooks.Open(ExcelFilePath,0,true,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
Excel.Sheets worksheets = workbook.Worksheets;
//-----------
}
catch(System.Exception ex)
{
//---
}
finally
{
try
{
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel = null;
}
catch(System.Exception ex)
{
//----
}
}
}
以上程序在大多数的情况下能正常的结束开启的excel线程,但是也有不能结束的情况,经过我很长时间的摸索,发现当excel中含有日期函数,如=TODAY()时,excel一定不能结束,请高人指点迷津!万分感谢!!!
补充:.NET技术 , C#