需要发烧,我创建了一个可以打开多个 Word 文档的桌面应用程序。但是在这里我面临一个问题,即当第二个文档打开时,第一个文档的退出事件在没有关闭该文档的情况下触发。
以下是我的代码
private void CreateNewProcessForEachDocument()
{
try
{
docProcess = new Process();
docProcess.StartInfo = new ProcessStartInfo(string.Concat(folderPath, fileName));
docProcess.EnableRaisingEvents = true;
docProcess.Exited += new EventHandler(docProcess_Exited);
docProcess.Start();
docProcess.WaitForExit();
docProcess.Close();
}
catch (Exception ex)
{
throw ex;
}
}
private void docProcess_Exited(object sender, EventArgs e)
{
try
{
var client = new ValidateClientClient();
byte[] fileData = File.ReadAllBytes(string.Concat(folderPath, fileName));
bool fileSaved = client.SaveDocument(fileData, fileName, username);
string filePath = Path.GetFullPath(string.Concat(folderPath, fileName));
if (fileSaved && File.Exists(filePath))
{
File.Delete(filePath);
}
}
catch (Exception ex)
{
throw ex;
}
}