我在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;
}
}
答案 0 :(得分:0)
如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();
}