您好,下面的代码正在运行,但如果其中一个程序已经打开,它将为 GetProcessByName 行抛出一个空异常。
如果进程已经在运行,我如何正确跟踪进程?
string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SomeFolder\\Folder\\Output");
string fname = System.IO.Path.Combine(path, Title); //<--- Title property will be like text.xlsx, test.docx etc)
Process sproc = Process.Start(fname);
string pname = sproc.ProcessName;
Process info = Process.GetProcessesByName(pname).FirstOrDefault();
using (Process eProcess = info)
{
eProcess.MainWindowTitle.Contains(fname);
eProcess.WaitForExit();
//Do Other Stuff
}