How can the application (PdCommon.Application) be closed in C#?

321 views Asked by At

I have the following code snippet in C# to open a PowerDesigner Model and I would like to close / exit the PowerDesigner application instance but I do not know how?

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;
  }
}
1

There are 1 answers

0
Fernando Vieira On

As commented by pascal, you should close the model, the workspace, and then, kill the process. DonĀ“t forget to add PdWSP (workspace model) reference, and System.Diagnostics using declaration. The process name may be different depending on the PD version.

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();
}