2015-06-16 18 views
0

我在C#中有下面的代碼片斷來打開一個PowerDesigner模型,我想關閉/退出PowerDesigner應用程序實例,但我不知道如何?應用程序(PdCommon.Application)如何在C#中關閉?

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

在您目前的情況下,您沒有「關閉」應用程序會發生什麼?也許你只需要關閉工作區:'pdApplication.ActiveWorkspace.Close(true)'。 – pascal

+0

ActiveDocument沒有Close方法。也許ActiveWorkspace必須被轉換爲另一個對象類? – user2722077

+0

PowerDesigner進程仍然存在於當前狀態的背景中。 – user2722077

回答

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