PDFCreator API doesn't works sometimes

Hi,

I am using PDFCreator API to creat pdf file in my project. However, I found that some of the API does not work all the time. And I have to add time delay between every API functions.

Anyone can help me about this? Here is some of my code:(Now there is no delay, and will not work. If I add some dealy between each function, it will work)

// Start PDF Creator                                                                                      
iResult = PDFCreator_New_clsPDFCreator (NULL, 1, LOCALE_NEUTRAL, 0, &g_hPDFCreator);                      
iResult = PDFCreator__clsPDFCreatorcStart (g_hPDFCreator, NULL, "/NoProcessingAtStartup", VFALSE, NULL);  
                                                                                                          
// Configure the setting                                                                                  
iResult = PDFCreator__clsPDFCreatorSetcOption (g_hPDFCreator, NULL, "UseAutosave", var_1);                
iResult = PDFCreator__clsPDFCreatorSetcOption (g_hPDFCreator, NULL, "UseAutosaveDirectory", var_1);       
iResult = PDFCreator__clsPDFCreatorSetcOption (g_hPDFCreator, NULL, "UAutosaveFormat", var_0);            
iResult = PDFCreator__clsPDFCreatorcClearCache (g_hPDFCreator, NULL);                                     
                                                                                                          
                                                                                                          
                                        
iResult = PDFCreator__clsPDFCreatorSetcOption (g_hPDFCreator, NULL, "AutosaveDirectory", *var_filepath);  
iResult = PDFCreator__clsPDFCreatorSetcOption (g_hPDFCreator, NULL, "AutosaveFilename", *var_filename);    
                                                                                                           
                                                                                                                                                                                                         
// Start Print File                                                                                       
iResult = PDFCreator__clsPDFCreatorcPrintFile (g_hPDFCreator, NULL, acFileSelect);                        
iResult = PDFCreator__clsPDFCreatorSetcPrinterStop (g_hPDFCreator, NULL, VFALSE);                         
                                                                                                          
                                                                                                          
// Release and Close                                                                                      
iResult = PDFCreator__clsPDFCreatorcClearCache (g_hPDFCreator, NULL);                                     
iResult = PDFCreator__clsPDFCreatorcClose (g_hPDFCreator, NULL, NULL);                                    
Delay (0.5);                                                                                              
                                                                                                          
                                                                                                          
CA_DiscardObjHandle(g_hPDFCreator);