我在 C# 中有以下代码片段来打开 PowerDesigner 模型,我想关闭/退出 PowerDesigner 应用程序实例,但我不知道怎么做?
PdCommon.Application pdApplication = null;
try{
//Creating PD Application object...
pdApplication = new PdCommon.Application();
//Opening the relevant models of a dedicated directory
String[] files = System.IO.Directory.GetFiles(ldmSourceDirectory);
foreach (String curFile in files){
if(curFile.EndsWith(".cdm")){
pdApplication.OpenModel(@curFile, PdCommon.OpenModelFlags.omf_DontOpenView);
}
}
//Doing some operations...
}finally{
if (pdApplication != null){
//Closing models
foreach (PdCDM.Model curPDModel in pdApplication.Models){
curPDModel.Close(false);
}
//But how can I close the application?
pdApplication = null;
}
}
正如 pascal 所评论的那样,您应该关闭模型、工作区,然后终止该过程。不要忘记使用声明添加 PdWSP(工作区模型)引用和 System.Diagnostics 。进程名称可能因 PD 版本而异。
PdCommon.Application pd = new PdCommon.Application();
var pdm = (PdPDM.Model)pdApplication.OpenModel(fileName);
var wsp = (PdWSP.Workspace)pdApplication.ActiveWorkspace;
pdm.Close(false);
wsp.Close(true);
pd = null;
// close powerdesigner processes
foreach(var process in Process.GetProcesses().Where(pr => pr.ProcessName == "PdShell16"))
{
process.Kill();
}