Issue 85875

Summary: Hang on Disposing XComponent/XDesktop
Product: App Dev Reporter: noviceprogram <novice.program>
Component: apiAssignee: AOO issues mailing list <issues>
Status: UNCONFIRMED --- QA Contact:
Severity: Trivial    
Priority: P3 CC: issues, novice.program
Version: 3.3.0 or older (OOo)   
Target Milestone: ---   
Hardware: PC   
OS: Windows Server 2003   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---

Description noviceprogram 2008-02-05 09:10:03 UTC
Hello,

I am using OO to convert PPTs/ODPs to multiple PDFs(generating a pdf per slide 
of PPT). I use C# as my programming language. I use this utility from a 
windows service to convert PPTs to PDFs and I always make sure that OO is not 
called from multiple threads. I have written the following code to do so. but 
when ever i try to dispose/terminate some thing(such as xcomponent/xdesktop 
object) OO hangs. Please note that this code is working on Windows XP and 
problem occurs only to Win2K3. I have looked into bug 79541 as well but this 
does not help either because the hang seems like OS specific now.
I have tried using XCloseable's close as well but it also hangs.

The code follows:

XComponent xComponent = null; 
XComponentLoader xComponentLoader = null; 

try 
{ 
// Get the component Loader for the OO. 
xComponentLoader = this.GetComponentLoader(); 

PropertyValue[] loadProps = new PropertyValue[1]; 
PropertyValue asHidden = new PropertyValue(); 
string pptPath = “file:///C:/Test.ppt”; 

asHidden.Name = "Hidden"; 
asHidden.Value = new uno.Any(true); 
loadProps[0] = asHidden; 

xComponent = xComponentLoader.loadComponentFromURL(pptPath, "_blank", 0, 
loadProps); 

unoidl.com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier 
= (unoidl.com.sun.star.drawing.XDrawPagesSupplier)xComponent; 

// XDrawPages inherits from com.sun.star.container.XIndexAccess 
unoidl.com.sun.star.drawing.XDrawPages xDrawPages 
= xDrawPagesSupplier.getDrawPages(); 

// get the page count for standard pages 
int slideCount = xDrawPages.getCount(); 

xComponent.dispose(); 

// The following way is very slow, but i could not find a better 
// way to do this. 
for (int index = 0; index < slideCount; ++index) 
{ 

pdfOutPath += outFileName + "_" + index + ".pdf"; 
ooOutPath = ToOOURL(pdfOutPath); 

xComponent = xComponentLoader.loadComponentFromURL(pptPath, 
"_blank", 0, loadProps); 

while (xComponent == null) 
{ 
/Let the component load. 
System.Threading.Thread.Sleep(1000); 
} 

xDrawPagesSupplier = (unoidl.com.sun.star.drawing.XDrawPagesSupplier)
xComponent; 

// XDrawPages inherits from com.sun.star.container.XIndexAccess 
xDrawPages = xDrawPagesSupplier.getDrawPages(); 

XStorable xstorable = (XStorable)xComponent; 

// Remove all the slides except this one. 
for (int removeSlide = slideCount - 1; removeSlide >= 0; --removeSlide) 
{ 
if (removeSlide != index) 
{ 
unoidl.com.sun.star.drawing.XDrawPage removePage 
= (unoidl.com.sun.star.drawing.XDrawPage) 
xDrawPages.getByIndex(removeSlide).Value; 

// Remove the Slide. 
xDrawPages.remove(removePage); 
} 
} 

PropertyValue[] props = new PropertyValue[1]; 

props[0] = new PropertyValue(); 
props[0].Name = "FilterName"; 
props[0].Value = new uno.Any(“impress_pdf_export”); 


// Store to the given path. 
xstorable.storeToURL(ooOutPath, props); 

xComponent.dispose();  // This line causes problem
} 
} 
catch (System.Exception e) 
{ 
string errorStr = "Can't Convert Using Open Office"; 
} 
finally 
{ 


// Quit Open Office. 
((XDesktop)xComponentLoader).terminate();  // This line as well.
} 
[/b]
Comment 1 jsc 2008-02-05 12:37:27 UTC
query the XComponent or XCloseable and use close 
Comment 2 jsc 2008-02-05 12:55:53 UTC
change prio, no P1

please use default priorities if you are not sure which you have to use.
Comment 3 jsc 2008-02-05 12:57:39 UTC
jsc -> as: maybe you want to comment this issue. I would say the right approach
is to use XCloseable as mentioned before. But anyway the office shouldn't crash.
Comment 4 syoungstephen 2008-02-05 18:45:27 UTC
I have the same issue when running on Windows 2003.

Using XCloseable calls Dispose anyway, which then hangs without returning and
with no exception.
Comment 5 benzman81 2010-07-07 12:05:50 UTC
Hi,
i had the same problem. If I do the disposal in a new thread, then it seems to work.

I hope that helps.

Regards,
Markus

p.s.: Below the code I use.

try {
  new Thread() {
    public void run() {
      xComponent.dispose()
    }
  }.start();
}
catch (Exception e) {
  e.printStackTrace();
}
Comment 6 Rob Weir 2013-07-30 02:38:24 UTC
Reset assignee on issues not touched by assignee in more than 1000 days.