0

我在 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;
  }
}
4

1 回答 1

0

正如帕斯卡所说,您应该关闭模型、工作区,然后终止该进程。不要忘记添加 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();
}
于 2016-12-08T02:34:06.527 回答