2016-03-02 26 views
1

我使用Windows服務中的Amyuni pdf庫,該服務以本地系統帳戶運行。以下是我用於打印的代碼。如何初始化Amyuni Pdf庫的多個實例?

private void Initialize() 
    { 
     acPDFCreatorLib.Initialize(); 
     acPDFCreatorLib.SetLicenseKey(licenseTo, activationCode); 
    } 

......打印PDF

using (FileStream file1 = new FileStream(fileName, FileMode.Open, FileAccess.Read)) 
       using (IacDocument doc1 = new IacDocument()) 
       { 
        doc1.Open(file1, ""); 
        doc1.AttributeByName("Title").Value = documentName; 
        doc1.SetAttributeForMultipleSelection("UnicodeFonts", true, false); 
        doc1.Copies = printEvent.Copies; 
        bool printed = doc1.Print(printerName, false); 
        PrintSystemJobInfo PrintSystemJobInfo = GetPrintJob(printerName, fileName); 
        if (printed) 
        { 
         Logger.Log(string.Format("[AMYUNI] PDF' {0} ' printed using printer {1}", documentName, printerName)); 
         return true; 
        } 
        return false; 
       } 

對於某些打印機 'doc1.Print(PRINTERNAME,假);'在不工作時,它不返回結果。用於調用打印函數的線程永遠不會返回。所以我們不能識別錯誤。

現在,我們正在計劃的解決方案是爲不同線程中的每臺打印機初始化amyuni庫實例。有了這個,我們將能夠使我們的解決方案適用於其他打印機,即使它被單個打印機阻止(amyuni庫凍結不響應)。

對於這個我們如何初始化庫的多個實例?

回答

3

這個調用保持原樣,但在主線程只

private void Initialize() 
    { 
     acPDFCreatorLib.Initialize(); 
     acPDFCreatorLib.SetLicenseKey(licenseTo, activationCode); 
    } 

,其餘部分進入在單獨的線程:

using (FileStream file1 = new FileStream(fileName, FileMode.Open, FileAccess.Read)) 
       using (IacDocument doc1 = new IacDocument()) 
       { 
        doc1.Open(file1, ""); 
        doc1.AttributeByName("Title").Value = documentName; 
        doc1.SetAttributeForMultipleSelection("UnicodeFonts", true, false); 
        doc1.Copies = printEvent.Copies; 
        bool printed = doc1.Print(printerName, false); 
        PrintSystemJobInfo PrintSystemJobInfo = GetPrintJob(printerName, fileName); 
        if (printed) 
        { 
         Logger.Log(string.Format("[AMYUNI] PDF' {0} ' printed using printer {1}", documentName, printerName)); 
         return true; 
        } 
        return false; 
       } 

根據您的工作流程,您可能需要以確保在該實例的打印完成之前不會處理PDF Creator IacDocument實例。

聲明:此答案由Amyuni Technologies的員工提供。

+1

我們已經在不同的線程中使用它。執行日誌如下。 - [螺紋11]初始化acPDFCreatorLib - [螺紋14]打印PDF ' - [螺紋5]初始化acPDFCreatorLib - [螺紋15]打印PDF' 但似乎在高電平它正在使用哪個我創建相同的參考當我們使用'acPDFCreatorLib.Initialize();' }進行初始化時,如果acPDFCreatorLib根據打印機上的問題而崩潰,它也會停止對其他打印機工作。你能解釋一下它是如何工作的嗎 – Charith

+0

@charithsoori如果你的打印機使用假脫機程序服務,那麼如果一個打印作業崩潰,所有其他待處理的作業將會遇到同樣的命運。 – yms

+0

「但它似乎在高層次上使用相同的參考文獻」我不明白你的意思......你正在創建文檔類的實例,所以只有你可以告訴你是否在所有文檔中使用相同的參考線程與否。 – yms