#region Kill Special Excel Process
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
//推荐这个方法,找了很久,不容易啊
public void KillSpecialExcel(Excel.Application m_objExcel)
{
try
{
if (m_objExcel != null)
{
int lpdwProcessId;
GetWindowThreadProcessId(new IntPtr(m_objExcel.Hwnd), out lpdwProcessId);
System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
}
}
catch (Exception ex)
{
Console.WriteLine("Delete Excel Process Error:" + ex.Message);
}
}
#endregion
这似乎是一个完美的解决方案了,但是速度实在不敢保证,而且耗费的内存和CPU资源也比较多。
对于用户少较少的应用还可以凑合,并发多了,真不敢想象。