public static void ReleaseExcelMemoryResource()
{
System.Diagnostics.Process[] aobjProcessExcel =
System.Diagnostics.Process.GetProcessesByName("excel");
var LinqExcelProess = from excelprocess in aobjProcessExcel
orderby excelprocess.StartTime descending
select excelprocess;
LinqExcelProess.First().Kill();
}
.Net Framework 3.0以下の環境はProcessオブジェクトの開始時間(StartTime)を降順にソートする方法を紹介します。
public class ProcessDateTimeComparer : IComparer
{
public int Compare(object x, object y)
{
//Process型以外の比較はエラー
if (!(x is System.Diagnostics.Process) || !(y is System.Diagnostics.Process))
throw new ArgumentException();
System.Diagnostics.Process process1 = (System.Diagnostics.Process)x;
System.Diagnostics.Process process2 = (System.Diagnostics.Process)y;
return process2.StartTime.CompareTo(process1.StartTime);
}
}
使い方は:
Array(aobjProcessExcel, new ProcessDateTimeComparer());
0 件のコメント:
コメントを投稿